preprocessor question

N

Neil Zanella

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
 
R

Richard Heathfield

Neil said:
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.)
 
R

Richard Heathfield

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

Neil said:
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.
 
G

Grumble

Neil said:
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.)
 
E

Eric Sosman

Richard said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top