Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utcs!mnetor!seismo!caip!cbmvax!vu-vlsi!colin From: colin@vu-vlsi.UUCP Newsgroups: net.lang.c Subject: sizeof "string"? multi-line macro usage? Message-ID: <343@vu-vlsi.UUCP> Date: Sat, 12-Jul-86 14:44:03 EDT Article-I.D.: vu-vlsi.343 Posted: Sat Jul 12 14:44:03 1986 Date-Received: Sun, 13-Jul-86 10:18:24 EDT Organization: Villanova Univ. EE Dept. Lines: 48 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. This worked great when compiled on Pyramid C, VAX VMS C, and Lattice C on a PC. Then I ran into the Regulus C compiler (Regulus 4.2C) which is truly brain-damaged in many respects; as far as I can tell, its sizeof returns a random value when given a string. So is it just Regulus that's screwed up, or do I have to explicitly declare char prompt[] = PROMPT; and then take sizeof(prompt)? (The latter _does_ work in Regulus.) 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); All the other compilers I've used have no trouble with this. (By not allowing multi-line macro usage, Lattice is screwing with the usually transparent interchangeability of functions and macros...) Anyone know the correct answer to these questions? Thanks... -Colin Kelley ..{cbmvax,pyrnj,psuvax1}!vu-vlsi!colin