Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!samsung!munnari.oz.au!labtam!foster!cbp From: cbp@foster.avid.oz (Cameron Paine) Newsgroups: comp.std.c Subject: Evaluation of expressions involving string literals Summary: What does ("literal" + 2) point to? Keywords: string literal; expression; pointer arithmetic; broken compiler? Message-ID: <1990Oct11.064854.12867@foster.avid.oz> Date: 11 Oct 90 06:48:54 GMT Organization: Avid Systems Pty Ltd, Melbourne, Australia. Lines: 34 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@foster.avid.oz - ACSnet cbp@foster.avid.oz.au - Internet ...!{hplabs,mcvax,nttlab,ukc,uunet}!munnari!foster.avid.oz.au!cbp - UUCP