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

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

  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. 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. Showjumper
    Replies:
    2
    Views:
    1,793
    Showjumper
    Aug 2, 2003
  2. , India

    inline function vs function-like macro

    , India, Mar 6, 2007, in forum: C Programming
    Replies:
    2
    Views:
    622
    Flash Gordon
    Mar 6, 2007
  3. Casey Hawthorne
    Replies:
    1
    Views:
    700
    Arne Vajhøj
    Mar 18, 2009
  4. Grant Schenck
    Replies:
    9
    Views:
    182
    [MSFT]
    Apr 26, 2005
  5. Ted Byers
    Replies:
    23
    Views:
    412
    Peter J. Holzer
    Nov 15, 2008
Loading...

Share This Page