Connecting Tech Pros Worldwide Forums | Help | Site Map

extern void a;

ais523
Guest
 
Posts: n/a
#1: Sep 8 '08
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.

--
ais523

Harald van =?UTF-8?b?RMSzaw==?=
Guest
 
Posts: n/a
#2: Sep 8 '08

re: extern void a;


On Mon, 08 Sep 2008 12:16:36 -0700, ais523 wrote:
Quote:
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.
Quote:
[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.
Closed Thread


Similar C / C++ bytes