Evaluation of expressions involving string literals
Cameron Paine
cbp at foster.avid.oz
Thu Oct 11 16:48:54 AEST 1990
I'm porting some code to an ANSI-conforming compiler and have encountered
an anomaly which my reading of K&R(2) and H&S(2) hasn't resolved. In the
original code, I used many expressions (the reason for doing this is not
relevant) such as:
char *cptr;
cptr = "XYhello, world!" + 2;
which has traditionally rendered:
*cptr == 'h' /* because cptr => "hello, world!" */
Under the ANSI-conforming compiler, I find that:
*cptr == 'X' /* because cptr => "XYhello, world!" */
Experimentation has revealed that:
cptr = "XYhello, world!";
cptr += 2;
achieves the result I'm after but this is of little use to me.
The question then is whether the new compiler's behaviour is correct. The
documentation I have implies that it isn't but I'd like to hear what the
lawyers think.
Thanks.
Cameron
--
cbp at foster.avid.oz - ACSnet
cbp at foster.avid.oz.au - Internet
...!{hplabs,mcvax,nttlab,ukc,uunet}!munnari!foster.avid.oz.au!cbp - UUCP
More information about the Comp.std.c
mailing list