Path: utzoo!utgpu!watserv1!watmath!att!rutgers!usc!zaphod.mps.ohio-state.edu!rpi!leah!bingvaxu!vu0310 From: vu0310@bingvaxu.cc.binghamton.edu (R. Kym Horsell) Newsgroups: comp.lang.c Subject: Re: stupid compilers Message-ID: <3932@bingvaxu.cc.binghamton.edu> Date: 3 Sep 90 00:29:25 GMT References: <163@prodix.liu.se> <24700008@sunb0.cs.uiuc.edu> Reply-To: vu0310@bingvaxu.cc.binghamton.edu.cc.binghamton.edu (R. Kym Horsell) Organization: SUNY Binghamton, NY Lines: 30 In article <24700008@sunb0.cs.uiuc.edu> mccaugh@sunb0.cs.uiuc.edu writes: \\\ > Since un-initialized ptrs so often lead to segmentation faults, here is my >guess as to what happened. The first declaration (char line [];) must have >initialized variable 'line' as a char-ptr to some 0-length area, while the >second declaration (char *line;) left 'line' un-initialized. Hence the value >of 'line' in the first case was legitimate -- even if it addressed 0-length \\\ Your analysis seems substantially correct -- but why guess? Try running: main(){ char a[]; char *b; printf("%d\n",sizeof(a)); printf("%d\n",sizeof(b)); } Output: 0 4 The *complier* sure thinks ``a'' is zero length -- if any string copy is done there you will essentially be copying ``above the stack pointer'' (if nothing else is declared local). This *may*, but not necessarily, cause a trap (depends on the hardware). -Kym Horsell