Path: utzoo!mnetor!uunet!lll-winken!lll-lcc!ames!hao!oddjob!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.lang.c Subject: Re: C pointer problems in VMS. Message-ID: <10696@mimsy.UUCP> Date: 17 Mar 88 16:40:18 GMT References: <12464@brl-adm.ARPA> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 30 In article <12464@brl-adm.ARPA> V053MF43@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@mimsy.umd.edu Path: uunet!mimsy!chris