Suppose there's a variable foo
in another translation unit. The real type of foo
is — for whatever reason — unknown in my C++ unit. I need to pass the address of this variable foo
to a function bar
that accepts a void pointer.
A solution that works for me on my machine with Clang is:
void bar(void *);
extern "C" char foo; // foo is not really of type char
void function() {
bar(&foo);
}
My questions are:
- Is this legal? If not...
- ... what is a standard-conforming and portable way of achieving this? Why does gcc allow extern declarations of type void (non-pointer)? suggests declaring a variable of type
void
would be legal and appropriate in this situation. Clang, however, doesn't accept this solution.