Google
 
Webnews.only-4-geeks.com
Interesting places
news.only-4-geeks.com Forum Index » C

extern void a;

 
Jump to:  
 
ais523
PostPosted: 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
PostPosted: 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.
 

Page 1 of 1 .:.

Google
 
Webnews.only-4-geeks.com

Windows Update | C++ | C | PHP | JavaScript | Photoshop | Programming | Windows 2000 | Python | Windows XP | Object | Flash | Flash - ActionScript | Paint Shop Pro | Excel | PowerPoint | Access | Word | Windows 98 | Internet Explorer 6.0 | CorelDraw12 | Java | XML | asm x86 | Linux Mandrake | Linux RedHat | Outlook |  | news from newsgroups |_ | s

Web Templates

Awesome Website Templates ©

Ich Szatan - Leśmian Bolesław Podczas Świąt - Lipska Ewa Meble biurowe Lechoń Jan wiersze Hotele w Mediolanie