C pointer problems in VMS.

Chris Torek chris at mimsy.UUCP
Fri Mar 18 02:40:18 AEST 1988


In article <12464 at brl-adm.ARPA> V053MF43 at ubvmsc.cc.buffalo.EDU (Mike Ayers)
[who suffers from the horrid fate of a gibberish login :-) ] writes [edited]:
>I am working in VMS 4.7.

>char *wr(a) int a; { body }
>main() { printf(" %s ",wr(4)); }

Whether this will work depends on the `body'.

>main() {
> char b[12];
> b[0]='A';
> strcpy(((&b)+1),"rf!");

This call is wrong.  Clearly you meant `&b[1]' (or `b+1').  `&b' is, in
K&R C, illegal (and compiles with a warning about `& before array
ignored' on many systems).  According to the dpANS, `&b' should produce
an object of type `pointer to array 12 of char', or (char (*)[12]).
This is no doubt what your compiler is doing.  This object has the
wrong type for an argument to strcpy; that alone suffices to warrant
the code's failure.

(The real reason it failed is different.  In fact, on a Vax, this
produces the same object code as if you had written

	strcpy(b + 12, "rf!");

In other words, it scribbles all over the stack.)
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris at mimsy.umd.edu	Path:	uunet!mimsy!chris



More information about the Comp.lang.c mailing list