Why does gcc allow extern declarations of type void? Is this an extension or standard C? Are there acceptable uses for this?
I am guessing it is an extension, but
I've found the only legitimate use for declaring
extern void foo;
is when foo
is a link symbol (an external symbol defined by the linker) that denotes the address of an object of unspecified type.
This is actually useful because link symbols are often used to communicate the extent of memory; i.e. .text section start address, .text section length, etc.
As such, it is important for the code using these symbols to document their type by casting them to an appropriate value. For instance, if foo
is actually the length of a memory region:
uint32_t textLen;
textLen = ( uint32_t )foo;
Or, if foo
is the start address of that same memory region:
uint8_t *textStart;
textStart = ( uint8_t * )foo;
The only alternate way to reference a link symbol in "C" that I know of is to declare it as an external array:
extern uint8_t foo[];
I actually prefer the void
declaration, as it makes it clear that the linker defined symbol has no intrinsic "type."