Passing commas into macros

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Grey Plastic

    Passing commas into macros

    How do I pass text that contains a comma into a macro? For example, I
    have

    #define ATTRIBUTE(name, type) ...

    and I want to do

    ATTRIBUTE(trans itions, map<int,int>);

    However, the last comma is being interpretted as the macro argument
    delimiter, and I get the error

    macro "ATTRIBUTE" passed 3 arguments, but takes just 2

    Help?
  • Gianni Mariani

    #2
    Re: Passing commas into macros

    Grey Plastic wrote:[color=blue]
    > How do I pass text that contains a comma into a macro? For example, I
    > have
    >
    > #define ATTRIBUTE(name, type) ...
    >
    > and I want to do
    >
    > ATTRIBUTE(trans itions, map<int,int>);[/color]

    Try

    ATTRIBUTE(trans itions, (map<int,int>))

    Or, worst case

    typedef map<int,int> map_int_int;
    ATTRIBUTE(trans itions, map_int_int)

    [color=blue]
    >
    > However, the last comma is being interpretted as the macro argument
    > delimiter, and I get the error
    >
    > macro "ATTRIBUTE" passed 3 arguments, but takes just 2
    >
    > Help?[/color]

    Comment

    • Andrey Tarasevich

      #3
      Re: Passing commas into macros

      Grey Plastic wrote:[color=blue]
      > How do I pass text that contains a comma into a macro? For example, I
      > have
      >
      > #define ATTRIBUTE(name, type) ...
      >
      > and I want to do
      >
      > ATTRIBUTE(trans itions, map<int,int>);
      >
      > However, the last comma is being interpretted as the macro argument
      > delimiter, and I get the error
      >
      > macro "ATTRIBUTE" passed 3 arguments, but takes just 2
      > ...[/color]

      Use typedef-name for the type

      typedef map<int,int> TMapIntInt;
      ATTRIBUTE(trans itions, TMapIntInt);

      --
      Best regards,
      Andrey Tarasevich

      Comment

      • Derk Gwen

        #4
        Re: Passing commas into macros

        greyplastic@hot mail.com (Grey Plastic) wrote:
        # How do I pass text that contains a comma into a macro? For example, I
        # have
        #
        # #define ATTRIBUTE(name, type) ...
        #
        # and I want to do
        #
        # ATTRIBUTE(trans itions, map<int,int>);
        #
        # However, the last comma is being interpretted as the macro argument
        # delimiter, and I get the error

        In C, many of these kinds of constructs can be parenthesised
        and avoid irritating cpp. If in C++ (map<int,int>) is equivalent to
        map<int,int>, then you can use ATTRIBUTE(trans itions, (map<int,int>)) ;

        --
        Derk Gwen http://derkgwen.250free.com/html/index.html
        So....that would make Bethany part black?

        Comment

        Working...