self-printing and programming standards

utzoo!decvax!harpo!ihps3!ihuxr!lew utzoo!decvax!harpo!ihps3!ihuxr!lew
Wed Nov 3 19:55:25 AEST 1982


I suppose Steve Wagar was being jocular when he said, "I dare anyone
out there in net.land to do this with one of the preferred styles!",
but the relationship of this problem to programming standards is very
interesting.

I identified three levels of standards, hook-or-crook, beautified,
and standard C. Beautified means the program is a valid cb output.
I take standard to mean that characters are represented by their
backslash representations e.g.

	printf("\t\"blahblah\"\n");

That is: NO %c ... 34 shenanigans.

The word counts of my three solutions are:

      1      5    169 self1.c
     16     62    458 self2.c
     64    138   1345 self3.c

The expansion of 8:1 from hook-or-crook to standard is not out of line
with real world projects. The reflexive nature of the problem provides
an analogy to the support and maintenance required in big projects.

I found the standard version most interesting. To approach this
version I wrote a quote() function, which prints out the source
line required to assign the given constant character pointer to
the appropriate array element. This routine prints newlines as '\n',
tabs as '\t', and so on. It also prints the quotes and other stuff
around the string.

The interesting part is that I used quote(), not only in the program,
but to generate the program. This way I could hack the body, beautify
it, enquote it, and then insert the enquoted beautified body into the
beautified body. Voila!

I posted a copy of this one to net.sources.

Lew Mammel, Jr. ihuxr!lew



More information about the Comp.lang.c mailing list