|  | extern void a; |  | |
| | | ais523 |  |
| Posted: Mon Sep 08, 2008 7:16 pm Post subject: extern void a; |  |
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 Dijk |  |
| Posted: Mon Sep 08, 2008 7:16 pm Post subject: 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. |
| |
|
|