Some problem on macro declaration in C again

Discussion in 'C Programming' started by zhangyue.zl@gmail.com, Mar 10, 2006.

  1. Guest

    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?
     
    , Mar 10, 2006
    #1
    1. Advertising

  2. Michael Mair Guest

    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.
     
    Michael Mair, Mar 10, 2006
    #2
    1. Advertising

  3. Guest


    > 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/images/180x60/rediscover.png
     
    , Mar 10, 2006
    #3
  4. Micah Cowan Guest

    "" <> 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
     
    Micah Cowan, Mar 10, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dead RAM
    Replies:
    20
    Views:
    1,117
    John Harrison
    Jul 14, 2004
  2. D Senthil Kumar

    macro name from macro?

    D Senthil Kumar, Sep 20, 2003, in forum: C Programming
    Replies:
    1
    Views:
    582
    Jack Klein
    Sep 21, 2003
  3. sounak

    to get macro name from macro value

    sounak, Nov 22, 2005, in forum: C Programming
    Replies:
    17
    Views:
    504
    Mark McIntyre
    Nov 22, 2005
  4. Patrick Kowalzick
    Replies:
    5
    Views:
    477
    Patrick Kowalzick
    Mar 14, 2006
  5. Ò»Ê×Ê«

    A design problem I met again and again.

    Ò»Ê×Ê«, Apr 1, 2009, in forum: Python
    Replies:
    24
    Views:
    728
    Dennis Lee Bieber
    Apr 4, 2009
Loading...

Share This Page