Array indexing vs. pointers...

steve emmerson steve at umigw.MIAMI.EDU
Thu Oct 6 22:35:12 AEST 1988


In article <10699 at ulysses.homer.nj.att.com> ggs at ulysses.homer.nj.att.com 
(Griff Smith) writes:
>   (void) fprintf(stderr, "\
>Usage:   sltread [options] input-drive-name\n\
>Options: [-l] [-s] [-v] [-x] [-z] [-t tape-volume-number]\n\
>         [-d dataset-name] [-n dataset-number]\n\
>         [-i ignore-count] [-r record-count]\n");
>
>I grant that this is vulnerable to code hackers and naive
>pretty-printers messing up the alignment.  On the other hand, it is
>easier to see how everything lines up.

Nonsense.  Use instead:
#define	EPUTS(msg)	(void)fputs(msg, stderr)
    EPUTS("Usage:   sltread [options] input-drive-name\n");
    EPUTS("Options: [-l] [-s] [-v] [-x] [-z] [-t tape-volume-number]\n");
    EPUTS("         [-d dataset-name] [-n dataset-number]\n");
    EPUTS("         [-i ignore-count] [-r record-count]\n");

This has all the advantages -- and none of the disadvantages -- of the other.
In ANSII-C you could even have the macro append the newline.

Don't write vulnerable code (at least not without *very* good reason).
-- 
Steve Emmerson                     Inet: steve at umigw.miami.edu [128.116.10.1]
SPAN: miami::emmerson (host 3074::)      emmerson%miami.span at star.stanford.edu
UUCP: ...!ncar!umigw!steve               emmerson%miami.span at vlsi.jpl.nasa.gov
"Computers are like God in the Old Testament: lots of rules and no mercy"



More information about the Comp.lang.c mailing list