[net.lang.c] sizeof \"string\"? multi-line macro usage?

rbj%icst-cmr@smoke.UUCP (07/15/86)

	Question 1.
	
	Is it (portably) legal for sizeof to operate on a string
	constant?  I checked K&R, and they seem to have nothing to say
	about the subject.  Admittedly, string constants are weird
	because they're the only valid array constants in the language,
	right?  That is, they evaluate to pointers just like other
	arrays do, but they magically find some memory for themselves,
	whereas other arrays are only allocated memory when they're
	declared.  This came up because I have coded

	#define PROMPT "prog> "
	
	in an include file, and then later used 
	
	for (i = 0; i < sizeof(PROMPT) - 1; i++)
				/* indent to first char of input */
		putchar(' ');
	
	to get the proper indentation for error messages.  

Definitely! I have seen `write(1,"Hello World\n",sizeof "Hello World\n")'.
Of course, if you want indentation, why not use a tab?

	Question 2.
	
	Does ANSI say anything about macro usage spanning more than one line?  Lattice
	C has something like
	
	#define max(a,b) ((a > b) ? a : b)
	
	but then barfs when I use the macro over more than one line, like
	
	x = min(very-long-expression-here,
		another-very-long-expression-here);
	
You could always try a backslash after the comma, or use macros
for the arguments as well. You're right, it does sound brain damaged.

	(Root Boy) Jim Cottrell		<rbj@icst-cmr.arpa>
	Of course, you UNDERSTAND about the PLAIDS in the SPIN CYCLE --

levy@ttrdc.UUCP (07/18/86)

In article <2229@brl-smoke.ARPA>, rbj@icst-cmr (Root Boy Jim) writes:
>Definitely! I have seen `write(1,"Hello World\n",sizeof "Hello World\n")'.

But that puts out a null character, too!
-- 
 -------------------------------    Disclaimer:  The views contained herein are
|       dan levy | yvel nad      |  my own and are not at all those of my em-
|         an engihacker @        |  ployer or the administrator of any computer
| at&t computer systems division |  upon which I may hack.
|        skokie, illinois        |
 --------------------------------   Path: ..!{akgua,homxb,ihnp4,ltuxa,mvuxa,
	   go for it!  			allegra,ulysses,vax135}!ttrdc!levy