Greg Greg - 11 months ago 46
C Question

Is there a safe way to refer to linker-only symbols that without taking the address of void expressions?

A file has a series of void declarations used as

as follows:

extern void __flash_rwdata_start;

which are provided solely by the linker script as symbols referring to binary partitioning as follows (ie a pointer):

PROVIDE (__flash_rwdata_start = LOADADDR(.rwdata));

And this generates the following warning:

file.c:84:19: warning: taking address of expression of type 'void' [enabled by default]

As per the answer to question http​:// I've changed this as follows (the function which takes the pointers uses an
unsigned long*

extern unsigned long __flash_rwdata_start;

Now it occurs to me that the original definition had an implication of zero (or undefined) size, whereas the current definition does not, and unlike the answer to question 27263344 there is no "real underlying data type" that makes any logical sense.

Essentially I've defined a pointer that is valid, but does not point to a valid value, and thus it would be invalid to dereference.

Is there a safer or preferable way to avoid the warning, but without the idea of space being allocated, that can't be dereferenced?

Answer Source

One idea that comes to mind is to make the object's type be an incomplete struct, like:

extern struct never_defined __flash_rwdata_start;

This way the address will be valid, but, as long as the type is never defined, not dereferenceable.