stupid compilers

R. Kym Horsell vu0310 at bingvaxu.cc.binghamton.edu
Mon Sep 3 10:29:25 AEST 1990


In article <24700008 at sunb0.cs.uiuc.edu> mccaugh at 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



More information about the Comp.lang.c mailing list