[comp.std.c] Question on backslash in string in define

6sigma2@polari.UUCP (Brian Matthews) (09/09/90)

If I have the following:

#define STR "12\
34"
char *x = STR;

what should x point to? "1234", "124", "hello world" :-), or is it
undefined?

Thanx
-- 
Brian L. Matthews	blm@6sceng.UUCP

henry@zoo.toronto.edu (Henry Spencer) (09/10/90)

In article <2480@polari.UUCP> 6sigma2@polari.UUCP (Brian Matthews) writes:
>If I have the following:
>
>#define STR "12\
>34"
>char *x = STR;
>
>what should x point to? "1234", "124", "hello world" :-), or is it
>undefined?

It is perfectly well defined.  The backslash-newline sequence vanishes
completely before anything else is done.  x points to "1234".
-- 
TCP/IP: handling tomorrow's loads today| Henry Spencer at U of Toronto Zoology
OSI: handling yesterday's loads someday|  henry@zoo.toronto.edu   utzoo!henry

6sigma2@polari.UUCP (Brian Matthews) (09/11/90)

In article <1990Sep9.224807.17776@zoo.toronto.edu> henry@zoo.toronto.edu (Henry Spencer) writes:
|In article <2480@polari.UUCP> 6sigma2@polari.UUCP (Brian Matthews) writes:
|>#define STR "12\
|>34"
|>char *x = STR;
|It is perfectly well defined.  The backslash-newline sequence vanishes
|completely before anything else is done.  x points to "1234".

Yep.  I thought that was the case, but I couldn't find it anywhere in
the standard.  I didn't think of looking in the translation phase
section, where it's spelled out very clearly.  Sigh.

Anyways, just for everyone's information, the Microsoft C compiler
that comes with SCO's version of Unix botches this.  It appears to
escape the first character of the next line (so in fact, my question
wasn't even correct.)

Thus,
#define STR "1\
\n2\n"

defines STR as "1\\n2\n", where it should define it as "1\n2\n"

Another of the vast array of reasons to avoid Microsoft C...
-- 
Brian L. Matthews	blm@6sceng.UUCP

seanf@sco.COM (Sean Fagan) (09/13/90)

In article <2483@polari.UUCP> 6sigma2@polari.UUCP (Brian Matthews) writes:
>Anyways, just for everyone's information, the Microsoft C compiler
>that comes with SCO's version of Unix botches this.  It appears to
>escape the first character of the next line (so in fact, my question
>wasn't even correct.)

Uhm, I just tried it (/bin/cc, not cc_of_the_week 8-)), and it worked
properly.  The compiler did not change in that respect for UNIX 3.2;
however, versions of the compiler did change between XENIX and UNIX.  If
that's what you're using, then there is an update which will fix it.

-- 
Sean Eric Fagan  | "let's face it, finding yourself dead is one 
seanf@sco.COM    |   of life's more difficult moments."
uunet!sco!seanf  |   -- Mark Leeper, reviewing _Ghost_
(408) 458-1422   | Any opinions expressed are my own, not my employers'.