[Beowulf] multiline string literals...

Robert G. Brown rgb at phy.duke.edu
Tue Jan 13 20:20:33 EST 2004


On Tue, 13 Jan 2004, Michael Stein wrote:

> Probably because it's hard to tell the difference between the above and
> an unbalanced double quote character?  An unbalanced quote could
> eat a big hunk of your code and possibly without any error messages...

Yeah, but the stuff below has 2N-2 more opportunities to fail to close
a quote and several other opportunities to screw up, and it isn't any
more difficult than balancing {}'s across the miles of intervening code.

I was thinking it might have to do with internationalization or
something like that and not just somebody's opinion of what is easy or
hard to safely code.

> Try this instead:
> char usage = "\n"
> "Usage:  foobar [-h] [-v] -f barianfile\n"
> "   -h for help\n"
> "   -v for verbose\n"
> "   -f barianfile to specify your foo-bar-barian\n"
> " ";
> 
> See ANSI C standard section 6.1.4 String literals which says that
> adjacent strings literals are concatenated into a single string.

Sigh.  This works and thank you.  Of course just a big string WORKS, it
just complains every time the file is compiled and this shuts it up.
Ah, in the good old days you could often declare a constant string like
this (without complaint) and even write back into it without anything
complaining.  Of course in the good old days, code leaked like a sieve
and buffer overwrite attacks existed in nearly every daemon or
utility...

> PS: You need either *usage or usage[].  -Wall is your friend...

:-) I know, pointer to the data block.  Just sloppy typing in the
example by hand.  As you say, that too is what compilers are for -- to
help you find little buglets.

Thanks again.  I'll adopt your suggestion just so the compiler shuts up.
I hate programs that don't build perfectly clean.  Especially when I'm
writing them.  So eventually I am nagged out of deprecated habits...:-)

   rgb

-- 
Robert G. Brown	                       http://www.phy.duke.edu/~rgb/
Duke University Dept. of Physics, Box 90305
Durham, N.C. 27708-0305
Phone: 1-919-660-2567  Fax: 919-660-2525     email:rgb at phy.duke.edu



_______________________________________________
Beowulf mailing list, Beowulf at beowulf.org
To change your subscription (digest mode or unsubscribe) visit http://www.beowulf.org/mailman/listinfo/beowulf



More information about the Beowulf mailing list