Conditional Define

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Richard Bos

    #31
    Re: Conditional Define

    "Paul Mensonides" <leavings@comca st.net> wrote:
    [color=blue]
    > Jack Klein wrote:[/color]

    [ No, he didn't. Do not over-snip attributions. ]
    [color=blue][color=green][color=darkred]
    > >> Boost.Preproces sor can perform this operation in several ways.
    > >> Here's one:
    > >>
    > >> #include <boost/preprocessor/comparison/greater.hpp>
    > >> #include <boost/preprocessor/control/iif.hpp>[/color]
    > >
    > > And exactly what is that supposed to mean in comp.lang.c?[/color]
    >
    > Unlike the rest of Boost, Boost.Preproces sor is both a C and C++ library.[/color]

    And is this Boost Preprocessor written in, and _completely_ compatible
    with, ISO C? And is the source code readily available so we can check
    this?

    Richard

    Comment

    • Case

      #32
      Re: Conditional Define

      Peter Nilsson wrote:[color=blue]
      > Case <no@no.no> wrote in message news:<408d1816$ 0$571$e4fe514c@ news.xs4all.nl> ...[color=green]
      >>#define FUNCT10() ...........
      >>#define FUNCT20() ......
      >>#define FUNCT56() .........
      >>#define FUNCT.....
      >>
      >>#define FUNCT(x, y) FUNCT ## x (y)[/color]
      >
      >
      > ITYM:
      >
      > #define FUNCT10 20
      > #define FUNCT20 20
      > #define FUNCT34 20
      > #define FUNCT36 56
      >
      > #define CAT(x,y) x ## y
      > #define FUNCT(x) CAT(FUNCT,x)
      >
      > FUNCT(10)
      > FUNCT(20)
      > FUNCT(34)
      > FUNCT(36)
      >
      > #define A 36
      > FUNCT(A)
      >[/color]
      Yep, that's more like it. Thanks for the addition, I was a
      bit in a hurry yesterday.

      Kees

      Comment

      • BQ

        #33
        Re: Conditional Define

        "BQ" <caa_via_sto_to c_balulaz@APOCH ESTOlibero.it> ha scritto nel messaggio
        news:ph5jc.2264 0$Qc.919215@twi ster1.libero.it ...[color=blue]
        > Hello
        > Is there a way to declare 'FUNCT' via a define so that if its parameter x, a constant,[/color]
        is[color=blue]
        > greater than 35, it returns 56, if not, 20.
        > I would like that at compile time, not at run time.
        > So:
        > #define FUNCT(x) x>35?56:20
        > is not the answer to my question.
        > Could be something like
        > #define FUNCT(x) #if (x>35) 56 #else 20 #endif
        > Since the 'x' is a constant, this can be done by the preprocessor, so I suppose there's[/color]
        a[color=blue]
        > way to do it.
        > Maybe it's a stupid question but is there a solution to this issue?
        > Thank you in advance,
        > Marco Lazzaroni[/color]

        Thank you all for your useful replies that helped me in better understanding the
        preprocessor.
        After re-examining the problem many times I found out that it can be reduced to the need
        of writing:

        #define FUNCT(x) #if TEST(x) Y1(x) #else Y2(x) #endif

        But as clearly stated in the FAQ, 10.14, the preprocessor can't be called on itself.

        I have to use FUNCT(x) with about hundreds of different costant values for x. This
        prevents the use of the interesting ## directive for reasons of readability and
        re-usability of the code.
        Obviously there are many ways to achieve what I need with smarter coding, without need of
        macros. But my major issue is about code space and I can't choose this solution. So, since
        I can't even rely on the compiler's efficiency - as considered in some of the posts - I
        will write a small pre-preprocessor.

        Thank you all again! :-)

        Regards,
        Marco Lazzaroni


        Comment

        • Peter Nilsson

          #34
          Re: Conditional Define

          "Richard Bos" <rlb@hoekstra-uitgeverij.nl> wrote in message
          news:408dfd41.2 415489051@news. individual.net. ..[color=blue]
          > "Paul Mensonides" <leavings@comca st.net> wrote:[color=green]
          > >[color=darkred]
          > > >> #include <boost/preprocessor/comparison/greater.hpp>
          > > >> #include <boost/preprocessor/control/iif.hpp>
          > > >
          > > > And exactly what is that supposed to mean in comp.lang.c?[/color]
          > >
          > > Unlike the rest of Boost, Boost.Preproces sor is both a C and C++ library.[/color]
          >
          > And is this Boost Preprocessor written in, and _completely_ compatible
          > with, ISO C?[/color]

          It's not strictly conforming (it exceeds various minimum implementation limits), but it's
          close.
          [color=blue]
          > And is the source code readily available so we can check this?[/color]

          Yes. www.boost.org

          --
          Peter


          Comment

          • ZAPPLE

            #35
            Re: Conditional Define

            "BQ" <caa_via_sto_to c_balulaz@APOCH ESTOlibero.it> wrote in message news:<DMnjc.148 084$Kc3.4909378 @twister2.liber o.it>...[color=blue]
            > "BQ" <caa_via_sto_to c_balulaz@APOCH ESTOlibero.it> ha scritto nel messaggio
            > news:ph5jc.2264 0$Qc.919215@twi ster1.libero.it ...[color=green]
            > > Hello
            > > Is there a way to declare 'FUNCT' via a define so that if its parameter x, a constant,[/color]
            > is[color=green]
            > > greater than 35, it returns 56, if not, 20.
            > > I would like that at compile time, not at run time.
            > > So:
            > > #define FUNCT(x) x>35?56:20
            > > is not the answer to my question.
            > > Could be something like
            > > #define FUNCT(x) #if (x>35) 56 #else 20 #endif
            > > Since the 'x' is a constant, this can be done by the preprocessor, so I suppose there's[/color]
            > a[color=green]
            > > way to do it.
            > > Maybe it's a stupid question but is there a solution to this issue?
            > > Thank you in advance,
            > > Marco Lazzaroni[/color]
            >
            > Thank you all for your useful replies that helped me in better understanding the
            > preprocessor.
            > After re-examining the problem many times I found out that it can be reduced to the need
            > of writing:
            >
            > #define FUNCT(x) #if TEST(x) Y1(x) #else Y2(x) #endif
            >
            > But as clearly stated in the FAQ, 10.14, the preprocessor can't be called on itself.
            >
            > I have to use FUNCT(x) with about hundreds of different costant values for x. This
            > prevents the use of the interesting ## directive for reasons of readability and
            > re-usability of the code.
            > Obviously there are many ways to achieve what I need with smarter coding, without need of
            > macros. But my major issue is about code space and I can't choose this solution. So, since
            > I can't even rely on the compiler's efficiency - as considered in some of the posts - I
            > will write a small pre-preprocessor.
            >
            > Thank you all again! :-)
            >
            > Regards,
            > Marco Lazzaroni[/color]

            Hi Guys,
            I think the previous one is a very good example and explanation for your question
            ZAPPLE

            Comment

            Working...