object-like macro used like function-like macro

Discussion in 'C++' started by Patrick Kowalzick, Mar 14, 2006.

  1. Hi all,

    Is this valid? I do not find the case in the standard:

    void foo( int ) {}

    #define FOO foo

    int main()
    {
    FOO(0);
    return 0;
    }

    Kind regards,
    Patrick
     
    Patrick Kowalzick, Mar 14, 2006
    #1
    1. Advertisements

  2. Patrick Kowalzick wrote:
    > Is this valid? I do not find the case in the standard:
    >
    > void foo( int ) {}
    >
    > #define FOO foo
    >
    > int main()
    > {
    > FOO(0);
    > return 0;
    > }


    I am fairly perplexed as to your statement about not finding this "case in
    the standard". Did you expect to find precisely this code or any other
    explanation to make this legal or not? Where in the Standard did you
    look? 'FOO' is replaced with 'foo' in the code _following_ the definition
    of 'FOO' macro. Once the preprocessor is done with the code, you get

    "void foo(int){}int main(){foo(0);return 0;}"

    (I left the spaces where needed to separate the preprocessor tokens).
    What's invalid about that code?

    And what is "object-like macro" you're referring to in your subject line?

    V
    --
    Please remove capital As from my address when replying by mail
     
    Victor Bazarov, Mar 14, 2006
    #2
    1. Advertisements

  3. > Hi all,
    >
    > Is this valid? I do not find the case in the standard:
    >
    > void foo( int ) {}
    >
    > #define FOO foo
    >
    > int main()
    > {
    > FOO(0);
    > return 0;
    > }


    ARGH. I found my problem. Sorry, really stupid. It was something like:

    #ifdef THIS_IS_NOT_DEFINED
    #define FOO foo
    #else
    #define FOO()
    #endif

    - rather ugly.

    Thanks,
    Patrick
     
    Patrick Kowalzick, Mar 14, 2006
    #3
  4. Hello Victor,

    > I am fairly perplexed as to your statement about not finding this "case in
    > the standard".


    Sorry to be unprecise. What I do not find is, how a macro expansion is
    carried out. And even if my problem was a rather stupid one (see other
    post), I do not find the necessary paragraphs for the expansion rules.

    > Where in the Standard did you look?


    Chapter 16.

    > And what is "object-like macro" you're referring to in your subject line?


    Object-like and function-like macro is mentioned in 16.3p2,3.

    Thanks,
    Patrick

    > V
    > --
    > Please remove capital As from my address when replying by mail
     
    Patrick Kowalzick, Mar 14, 2006
    #4
  5. Patrick Kowalzick wrote:
    > Hello Victor,
    >
    >
    >>I am fairly perplexed as to your statement about not finding this "case in
    >>the standard".

    >
    >
    > Sorry to be unprecise. What I do not find is, how a macro expansion is
    > carried out. And even if my problem was a rather stupid one (see other
    > post), I do not find the necessary paragraphs for the expansion rules.


    16.3/8 and 16.3/9. I am surprised you didn't find it, considering that
    you read 16.3 apparently quite carefully.

    >>Where in the Standard did you look?

    >
    >
    > Chapter 16.


    Yep, it's there alright.

    >>And what is "object-like macro" you're referring to in your subject line?

    >
    >
    > Object-like and function-like macro is mentioned in 16.3p2,3.


    Gotcha. I never used those terms before and they'd slipped off my mind,
    obviously.

    V
    --
    Please remove capital As from my address when replying by mail
     
    Victor Bazarov, Mar 14, 2006
    #5
  6. >>>I am fairly perplexed as to your statement about not finding this "case
    >>>in
    >>>the standard".

    >>
    >>
    >> Sorry to be unprecise. What I do not find is, how a macro expansion is
    >> carried out. And even if my problem was a rather stupid one (see other
    >> post), I do not find the necessary paragraphs for the expansion rules.

    >
    > 16.3/8 and 16.3/9. I am surprised you didn't find it, considering that
    > you read 16.3 apparently quite carefully.
    >


    Yes, me too. The reason is quite easy. I was a little bit irritated by the
    wording:

    -macro expansion (16p4)
    -macro replacement (16.3, 16.3.8, 16.3.9,..)
    -macro redefinition (16.3.2, 16.3.3)

    In fact it is intuitive :).

    Regards,
    Patrick
     
    Patrick Kowalzick, Mar 14, 2006
    #6
    1. Advertisements

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. Showjumper
    Replies:
    2
    Views:
    2,094
    Showjumper
    Aug 2, 2003
  2. James Vanns
    Replies:
    7
    Views:
    7,676
    Evan Carew
    Jan 21, 2004
  3. Russell Shaw

    Function-like macro

    Russell Shaw, May 24, 2005, in forum: C Programming
    Replies:
    17
    Views:
    1,355
    Richard Bos
    May 27, 2005
  4. baumann@pan

    why function like macro doesn't work here?

    baumann@pan, Jul 8, 2005, in forum: C Programming
    Replies:
    8
    Views:
    589
    Sensei
    Jul 15, 2005
  5. , India

    inline function vs function-like macro

    , India, Mar 6, 2007, in forum: C Programming
    Replies:
    2
    Views:
    857
    Flash Gordon
    Mar 6, 2007
  6. Noob

    Redefining an object-like macro

    Noob, Dec 9, 2009, in forum: C Programming
    Replies:
    4
    Views:
    977
    Kaz Kylheku
    Dec 9, 2009
  7. Grant Schenck
    Replies:
    9
    Views:
    398
    [MSFT]
    Apr 26, 2005
  8. alex
    Replies:
    3
    Views:
    753
    Richard Cornford
    Dec 28, 2006
Loading...