Some problem on macro declaration in C again

Z

zhangyue.zl

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?
 
M

Michael Mair

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
 
Z

zhangyue.zl

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.
 
M

Micah Cowan

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
 

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
473,766
Messages
2,569,569
Members
45,044
Latest member
RonaldNen

Latest Threads

Top