extern void a;

A

ais523

Consider the following translation unit:

extern void a;
void* func(void)
{
static void* ap = &a;
return ap;
}

Is this strictly conforming C? (I've written something similar
recently, in a situation with system-specific code where I was using
nonstandard extensions freely, but I was wondering whether it was
legal in c.l.c-standard C.) Arguably, this translation unit itself is
legal (void is just being used the same way any other incomplete type
would be), but there's no way to produce any other combination
translation units in strictly conforming C which would combine with it
to form a strictly conforming program.
 
H

Harald van Dijk

Consider the following translation unit:

extern void a;
void* func(void)
{
static void* ap = &a;
return ap;
}

Is this strictly conforming C?

No, it isn't.
[snip]
Arguably, this translation unit itself is legal (void
is just being used the same way any other incomplete type would be), but
there's no way to produce any other combination translation units in
strictly conforming C which would combine with it to form a strictly
conforming program.

That might apply if you declare extern const void a;. With what you have
now, a is not an lvalue, because it has type void. You can take the
address of lvalues, of dereferenced pointers, and of functions. a is none
of those in your example.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,266
Messages
2,571,078
Members
48,772
Latest member
Backspace Studios

Latest Threads

Top