Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > preprocessor question

Reply
Thread Tools

preprocessor question

 
 
Neil Zanella
Guest
Posts: n/a
 
      11-06-2003

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

 
Reply With Quote
 
 
 
 
Richard Heathfield
Guest
Posts: n/a
 
      11-06-2003
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 : http://www.velocityreviews.com/forums/(E-Mail Removed)
"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
 
Reply With Quote
 
 
 
 
Richard Heathfield
Guest
Posts: n/a
 
      11-06-2003
[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 : (E-Mail Removed)
"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
 
Reply With Quote
 
Grumble
Guest
Posts: n/a
 
      11-06-2003
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.)

 
Reply With Quote
 
Eric Sosman
Guest
Posts: n/a
 
      11-06-2003
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.

--
(E-Mail Removed)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Compiler error occurred when try to use a flexible template expression in preprocessor definesCompiler error occurred when try to use a flexible template expression in preprocessor defines snnn C++ 6 03-14-2005 04:09 PM
preprocessor, token concatenation, no valid preprocessor token Cronus C++ 1 07-14-2004 11:10 PM
a question about preprocessor xuatla C++ 1 07-10-2004 11:03 AM
preprocessor implementation GURU question Dan W. C++ 9 12-04-2003 02:24 AM
Preprocessor's question C Programming 1 09-12-2003 05:32 PM



Advertisments