C puzzle
R.L.K.Dattatri
rlkd at opusys.UUCP
Thu Aug 24 10:14:03 AEST 1989
Here is a small puzzle.
The program below will compile and run on some compilers but will\
not compile on others.
main()
{
int *p;
p = (int *) malloc(1024);
test_it(p);
}
test_it (x)
int (*x)[];
/* If a dimension is specified all compilers will accept it */
{
int i;
for (i=0; i < 10; ++i)
(*x)[i] = i;
/* x++; */
}
The parameter 'x' in test_it without dimensions works on some compilers
but others complain incomplete array'.
I can understand that the compiler is trying to guess the size of the rows
in the array. But that should come only when the commented x++ is used.
Without the dimension all compilers generated an increment of 'int' size for
'x++' but with the dimension it was the size of dimension * int size.
Does ANSI specify anything in this regard?
|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
| Mr. R.L.K. Dattatri (408) 446-2110 (W) |~~~~~| |
| Opus Systems (408) 243-5140 (H) |_____| |
| 20863 Bldg 400 |\ | |/ |~~\ |
| Stevens Creek, Cupertino | \ [___|\ | | |
| California, 95014 \ | | |
| E-mail: {uunet,sun}!opusys!rlkd FAX: (408) 446-5009 \ |__/ |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
More information about the Comp.lang.c
mailing list