2 ms·
My C is rusty. I would have thought the former declared a pointer in the second member of the struct, i.e. typically a 4- or 8- byte field. edit: clarifying, I
by hughw 10y ago
My C is rusty. I would have thought the former declared a pointer in the second member of the struct, i.e. typically a 4- or 8- byte field.
edit: clarifying, I thought int somearray [] was the same as int* somearray.
- TazeTSchnitzel 10y agoI may be wrong, but I think someArray[] only does that for function parameters.
- kazinator 10y agoAlso for external declarations: /* file scope */ int a[]; /* later in same translation unit, or in another one: */ int a[42]; In this case, we get an "incomplete array type" after the first declaration. The storage size isn't known and so sizeof a cannot be computed. This is also a de facto kind of "flexible array", but not formally named such. For instance we can do this: /* In proprietary kernel source code */ /* Size deliberately unspecified */ extern struct driver driver_table[]; The proprietary kernel code is compiled into .o files and linked into a .a archive library. To complete the build, a driver table module must be added and some drivers. The module which defines driver_table can be open-source. It defines the size of driver_table by how many entries there actually are; users can configure as many or few drivers and re-build the kernel, without having to recompile the proprietary part in the .a archive. Unixes were shipped like this once upon a time. The "device major number" is just the position in the device table.
- pklausler 10y agoFormal arguments of array type are transformed into pointers.