On Fri, Jul 01, 2005 at 10:45:19AM +0200, Etienne Lorrain wrote: > The result of this funtion is 1, is there a C lawyer around?
The parameter is treated as unsigned* since an array is converted to a pointer when passed through a function. C99 says in 6.7.5.3: [#7] A declaration of a parameter as ``array of type'' shall be adjusted to ``qualified pointer to type'', where the type qualifiers (if any) are those specified within the [ and ] of the array type derivation. > $ cat tmp.c > unsigned fct (unsigned array[10]) These prototypes are all equivalent, and any sized array (or just a plain pointer) can be passed to them: unsigned fct (unsigned array[10]); unsigned fct (unsigned array[]); unsigned fct (unsigned* array); > { > return sizeof(array) / sizeof(array[0]); > } Therefore what you're testing is sizeof(unsigned*)/sizeof(unsigned) which is 1 on x86 and most other 32-bit targets (but 2 on e.g. x86_64) Hope that helps, jon