Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Some problem on macro declaration in C again

Reply
Thread Tools

Some problem on macro declaration in C again

 
 
zhangyue.zl@gmail.com
Guest
Posts: n/a
 
      03-10-2006
Before I thought C is simple and convient , but now I dont think
so.There is really some ugly thing in C.Today I see some macro
declaration like this:

void va_end (va_list); /* Defined in gnulib */
#define va_end(AP)

Even if we dont consider what va_end do,but doesnt it cause some name
confliction as a result of its two appearances?

 
Reply With Quote
 
 
 
 
Michael Mair
Guest
Posts: n/a
 
      03-10-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) schrieb:
> Before I thought C is simple and convient , but now I dont think
> so.There is really some ugly thing in C.Today I see some macro
> declaration like this:
>
> void va_end (va_list); /* Defined in gnulib */
> #define va_end(AP)
>
> Even if we dont consider what va_end do,but doesnt it cause some name
> confliction as a result of its two appearances?


1) You are looking at the so-called implementation -- it is perfectly
free to do whatever it wants however it wants as long as it provides
you with the language and library facilities you are expecting.
2) You did not provide enough context, so it is perfectly possible
that these two "definitions" are mutually exclusive (e.g. by
conditional compilation).
3) OT here: The "gnulib" is not written in standard C. Not even the
parts which could have been written in standard C. They usually use
a language following the gnu89 or gnu99 standard.

Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
 
Reply With Quote
 
 
 
 
zhangyue.zl@gmail.com
Guest
Posts: n/a
 
      03-10-2006

> 2) You did not provide enough context, so it is perfectly possible
> that these two "definitions" are mutually exclusive (e.g. by
> conditional compilation).

Actually these codes come from early Linux's kernel ,version 0.11.
And I am sure that there's no other codes related to these two lines.
O,wait,there's also a invoking statement as below:

char * s;
va_end(s);

I dont think they can help something.
Absolutely,there's no conditional comilation statements.

> 3) OT here: The "gnulib" is not written in standard C. Not even the
> parts which could have been written in standard C. They usually use
> a language following the gnu89 or gnu99 standard.

The files are compiled with gcc,version about 1.4.x. I cant remember
clearly.
I dont know if it is compatabe with standard C.If not,maybe that can
explain.
--
http://www.mozilla.net.cn/spread/ima...rediscover.png

 
Reply With Quote
 
Micah Cowan
Guest
Posts: n/a
 
      03-10-2006
"(E-Mail Removed)" <(E-Mail Removed)> writes:

> Before I thought C is simple and convient , but now I dont think
> so.There is really some ugly thing in C.Today I see some macro
> declaration like this:
>
> void va_end (va_list); /* Defined in gnulib */
> #define va_end(AP)
>
> Even if we dont consider what va_end do,but doesnt it cause some name
> confliction as a result of its two appearances?


Many times, a library will provide both a function (as required by the
standard), and a function-like macro that does the same thing
(explicitly allowed by the Standard). In the case of va_end(), the
Standard specifically allows va_end() to be either a function /or/ a
macro /or/ both.

With code like the above, if you call va_end(ap), then you'll invoke
the macro, which apparently does nothing (but still must be provided,
per the Standard). If you call (va_end)(ap), you'll be guaranteed to
get the function (which probably also does nothing, in your
implementation).

However, (va_end)(ap) is explicitly not supported by the Standard, so
I don't really know why they bothered to provide a real function. For
other Standard functions that are allowed to be macros, though, that
style is the usual way to ensure that you really call a function, not
invoke a macro.

-Micah
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can a static function declaration conflict with a non-static declaration? nospam_timur@tabi.org C Programming 4 12-12-2006 10:26 PM
maxplusII error: a deferred constant declaration without a full declaration is not supported Noah VHDL 5 04-07-2006 02:34 PM
"virtual outside class declaration" and "declaration does not declare anything" kelvSYC C++ 6 05-17-2005 08:58 AM
Function declaration in class declaration Ovidesvideo C++ 4 12-10-2004 06:36 PM
Intel C++ 8.0 : declaration hides declaration Alex Vinokur C++ 4 04-05-2004 09:49 PM



Advertisments