Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!usc!ginosko!uunet!opusys!rlkd From: rlkd@opusys.UUCP (R.L.K.Dattatri) Newsgroups: comp.lang.c Subject: C puzzle Keywords: arrays, compilers Message-ID: <404@opusys.UUCP> Date: 24 Aug 89 00:14:03 GMT Organization: Opus Systems, Cupertino, CA Lines: 40 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 \ |__/ | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~