preprocessor question

Discussion in 'C Programming' started by Neil Zanella, Nov 6, 2003.

  1. Neil Zanella

    Neil Zanella Guest

    Hello,

    I would like to have the preprocessor form a string containing the value
    of INT_MAX from limits.h but I am fairly certain that this is impossible
    using C alone... yes I could call sprintf, but I would have liked some
    solution based on the preprocessor, so that I can have my string
    literal ready at compile time instead of at run time. Oh well..

    Thanks,

    Neil
    Neil Zanella, Nov 6, 2003
    #1
    1. Advertising

  2. Neil Zanella wrote:

    >
    > Hello,
    >
    > I would like to have the preprocessor form a string containing the value
    > of INT_MAX from limits.h but I am fairly certain that this is impossible
    > using C alone... yes I could call sprintf, but I would have liked some
    > solution based on the preprocessor, so that I can have my string
    > literal ready at compile time instead of at run time. Oh well..


    This is FAQ 11.17. See sig for URL.

    (Haven't checked online FAQ. It's in the book copy, for sure.)

    --
    Richard Heathfield :
    "Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
    C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
    K&R answers, C books, etc: http://users.powernet.co.uk/eton
    Richard Heathfield, Nov 6, 2003
    #2
    1. Advertising

  3. [Sorry if this is a duplicate. God bless KNode...grrr...]

    Neil Zanella wrote:

    >
    > Hello,
    >
    > I would like to have the preprocessor form a string containing the value
    > of INT_MAX from limits.h but I am fairly certain that this is impossible
    > using C alone... yes I could call sprintf, but I would have liked some
    > solution based on the preprocessor, so that I can have my string
    > literal ready at compile time instead of at run time. Oh well..


    See FAQ 11.17, which describes precisely how to do this. See my sig for the
    URL.

    --
    Richard Heathfield :
    "Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
    C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
    K&R answers, C books, etc: http://users.powernet.co.uk/eton
    Richard Heathfield, Nov 6, 2003
    #3
  4. Neil Zanella

    Grumble Guest

    Neil Zanella wrote:
    > I would like to have the preprocessor form a string containing the value
    > of INT_MAX from limits.h but I am fairly certain that this is impossible
    > using C alone... yes I could call sprintf, but I would have liked some
    > solution based on the preprocessor, so that I can have my string
    > literal ready at compile time instead of at run time. Oh well..


    This is Frequently Asked Question number 11.17

    http://www.eskimo.com/~scs/C-faq/q11.17.html

    (Strike two.)
    Grumble, Nov 6, 2003
    #4
  5. Neil Zanella

    Eric Sosman Guest

    Richard Heathfield wrote:
    >
    > Neil Zanella wrote:
    >
    > >
    > > Hello,
    > >
    > > I would like to have the preprocessor form a string containing the value
    > > of INT_MAX from limits.h but I am fairly certain that this is impossible
    > > using C alone... yes I could call sprintf, but I would have liked some
    > > solution based on the preprocessor, so that I can have my string
    > > literal ready at compile time instead of at run time. Oh well..

    >
    > This is FAQ 11.17. See sig for URL.
    >
    > (Haven't checked online FAQ. It's in the book copy, for sure.)


    Stringizing the macro's definition might not satisfy
    the O.P.'s need. The result might be any of "32767",
    "0x7fff", "077777", "__intmax", or even stranger strings.

    --
    Eric Sosman, Nov 6, 2003
    #5
    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. Dan W.
    Replies:
    9
    Views:
    331
    Paul Mensonides
    Dec 4, 2003
  2. xuatla
    Replies:
    1
    Views:
    366
    Denis Remezov
    Jul 10, 2004
  3. Cronus
    Replies:
    1
    Views:
    658
    Paul Mensonides
    Jul 15, 2004
  4. ³á³á³á³á

    Preprocessor's question

    ³á³á³á³á, Sep 12, 2003, in forum: C Programming
    Replies:
    1
    Views:
    331
    Martin Ambuhl
    Sep 12, 2003
  5. Charlie Zender

    C-preprocessor macro question

    Charlie Zender, Dec 24, 2003, in forum: C Programming
    Replies:
    3
    Views:
    455
    Richard Bos
    Dec 24, 2003
Loading...

Share This Page