what does _ARGS_ mean in C

Discussion in 'C' started by punith, Jun 12, 2009.

  1. punith

    punith New Member

    Joined:
    Sep 4, 2007
    Messages:
    18
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    ALP programmer
    Hi All,

    I came across this piece of code where the function declaration was like this

    Code:
    return_t mtp3_init  _ARGS_((mtp3_init_opt_t *, error_t *));
    
    What is the significance of _ARGS_ here.

    The function definition looks like this.

    Code:
    return_t mtp3_init
    #ifdef ANSI_PROTO
           (mtp3_init_opt_t *p_init_opt,
            error_t         *p_ecode)
    #else
           (p_init_opt,p_ecode)
            mtp3_init_opt_t *p_init_opt;
            error_t         *p_ecode;
    #endif
    
    does _ARGS_ change the way the function is called ?
     
  2. SaswatPadhi

    SaswatPadhi ~ Б0ЯИ Τ0 С0δЭ ~

    Joined:
    May 5, 2009
    Messages:
    1,342
    Likes Received:
    55
    Trophy Points:
    0
    Occupation:
    STUDENT !
    Location:
    Orissa, INDIA
    Home Page:
    http://www.crackingforfun.blogspot.com
    _ARGS_ is used to pass arguments into a func, in a generic way.

    This is used here to allow non-ANSI as well as ANSI C compilers to compile the program successfully.
    Old non-ANSI C style functions were defined like :

    Code:
    int sum(a,b)
    int a,b;
    {
          return (a+b);
    }
    But ANSI C uses the following style :
    Code:
    int sum(int a, int b)
    {
          return (a+b);
    }
    So, what exactly is done here is, no specific style is adopted, rather the arguments are passed in a generic method by using _ARGS_.
    Then using the #ifdef, we check if ANSI style can be used.
    If so, we define the func in ANSI C style using the arguments passed through _ARGS_, else we define the func in non-ANSI C style using the arguments passed through _ARGS_.

    :)
     
  3. punith

    punith New Member

    Joined:
    Sep 4, 2007
    Messages:
    18
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    ALP programmer
    Ok now i get it thanks a lot :)
     
  4. SaswatPadhi

    SaswatPadhi ~ Б0ЯИ Τ0 С0δЭ ~

    Joined:
    May 5, 2009
    Messages:
    1,342
    Likes Received:
    55
    Trophy Points:
    0
    Occupation:
    STUDENT !
    Location:
    Orissa, INDIA
    Home Page:
    http://www.crackingforfun.blogspot.com
  5. mayjune

    mayjune New Member

    Joined:
    Jun 14, 2009
    Messages:
    814
    Likes Received:
    33
    Trophy Points:
    0
    Occupation:
    Student
    Location:
    Pune,Delhi
    hey SaswatPadhi
    can you give my an example of how you would have written that a+b example using _ARGS_
    i am still not clear with the syntax...
    thanks...
     
  6. SaswatPadhi

    SaswatPadhi ~ Б0ЯИ Τ0 С0δЭ ~

    Joined:
    May 5, 2009
    Messages:
    1,342
    Likes Received:
    55
    Trophy Points:
    0
    Occupation:
    STUDENT !
    Location:
    Orissa, INDIA
    Home Page:
    http://www.crackingforfun.blogspot.com
    (First of all, note that you have to define the _ARGS_ macro and ANSI_PROTO yourself. It's not predefined.)

    Now, you can define the sum function this way :

    Declaration :
    Code:
    int sum _ARGS_((int a, int b));
    
    Definition :
    Code:
    int sum
    #ifdef ANSI_PROTO
        (int a, int b)
    #else
        (a, b)
        int a;
        int b;
    #endif
    
    I hope it's clear to you now. :)
     
    Last edited: Jun 15, 2009
  7. mayjune

    mayjune New Member

    Joined:
    Jun 14, 2009
    Messages:
    814
    Likes Received:
    33
    Trophy Points:
    0
    Occupation:
    Student
    Location:
    Pune,Delhi
    ah so if on a compiler which is ansi, it will replace the code with standard arguments style
    else it will replace it with old fashioned way.... as its a "macro"
    neat...
    thanks...
    do people actually use it? professionally?
     
  8. SaswatPadhi

    SaswatPadhi ~ Б0ЯИ Τ0 С0δЭ ~

    Joined:
    May 5, 2009
    Messages:
    1,342
    Likes Received:
    55
    Trophy Points:
    0
    Occupation:
    STUDENT !
    Location:
    Orissa, INDIA
    Home Page:
    http://www.crackingforfun.blogspot.com
    Yeah, I have seen numerous applications of this macro. (And yes, professionally.)

    The code mentioned in the first post of this thread, I think is for some kind of signaling.
    (I guess that from mtp3. MTP3 = Message Transfer Protocol 3)
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice