empty parameterized macro

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John Goche

    #1

    empty parameterized macro


    Hello,

    I would like to know whether there is any difference between
    the macro

    #define FOO

    and the parameterized macro taking no parameters

    #define FOO()

    What is the purpose of the empty parameter list in the latter?

    Thanks,

    JG

  • Hallvard B Furuseth

    #2
    Re: empty parameterized macro

    John Goche writes:
    I would like to know whether there is any difference between
    the macro
    >
    #define FOO
    >
    and the parameterized macro taking no parameters
    >
    #define FOO()
    They are called differently. The first is called as just FOO, the
    second is called as FOO(). With the second, 'FOO' without () after it
    is not expanded at all. If you want to define a constant, you'll
    typically define FOO. If you define something which evaluates at
    run-time, it looks more informative if you define FOO().

    #define FOO one
    #define BAR() two
    #define BAZ BAR
    Now the code
    FOO w BAR x BAR() y BAZ() z
    expands to
    one w BAR x two y two z

    --
    Hallvard

    Comment

    • aegis

      #3
      Re: empty parameterized macro


      Hallvard B Furuseth wrote:
      John Goche writes:
      I would like to know whether there is any difference between
      the macro

      #define FOO

      and the parameterized macro taking no parameters

      #define FOO()
      >
      Is that even allowed under c89?

      If so, chapter and verse please.

      --
      aegis

      Comment

      • Hallvard B Furuseth

        #4
        Re: empty parameterized macro

        aegis writes:
        >Hallvard B Furuseth wrote:
        >>John Goche writes:
        >>I would like to know whether there is any difference between
        >>the macro
        >> #define FOO
        >>and the parameterized macro taking no parameters
        >> #define FOO()
        >
        Is that even allowed under c89?
        If so, chapter and verse please.
        Huh? Why not? Ever head of systems where getchar() is a macro?

        Look up chapter and verse yourself if you think it's not allowed.
        The grammar is something like
        # define identifier(iden tifier-list<opt>) replacement-list new-line
        Note the <opt(optional ).

        --
        Hallvard

        Comment

        Working...