473,503 Members | 1,646 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

preprocessor question


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

Nov 13 '05 #1
4 1954
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 : bi****@eton.powernet.co.uk
"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
Nov 13 '05 #2
[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 : bi****@eton.powernet.co.uk
"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
Nov 13 '05 #3
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.)

Nov 13 '05 #4
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.

--
Er*********@sun.com
Nov 13 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

205
10452
by: Jeremy Siek | last post by:
CALL FOR PAPERS/PARTICIPATION C++, Boost, and the Future of C++ Libraries Workshop at OOPSLA October 24-28, 2004 Vancouver, British Columbia, Canada http://tinyurl.com/4n5pf Submissions
24
40040
by: Nudge | last post by:
I have an array, and an unrolled loop which looks like this: do_something(A); do_something(A); .... do_something(A); I thought: why should I type so much? I should write a macro. So I was...
4
1934
by: Jim Ford | last post by:
I have a single C file with the following code: int f2() { /* Blah-blah */ } int f1() { /* Blah-blah */
13
2086
by: Chris Croughton | last post by:
Is the following code standard-compliant, and if so what should it do? And where in the standard defines the behaviour? #include <stdio.h> #define DEF defined XXX int main(void) { int...
3
2008
by: Avin Patel | last post by:
Hi, I have written C# code. And I have used preprocessor / macro in it. I want to get the C# code after processing preprocessor, I have defined durcng compile time. How can I get this code? ...
32
2734
by: spibou | last post by:
Is the output of the C preprocessor deterministic ? What I mean by that is , given 2 compilers which conform to the same standard, will their preprocessors produce identical output given as input...
6
1603
by: ludovicd | last post by:
Hi to all, There is my question, Let's say I got a fonction which takes a numeric argument long enough so that there has to be spaces in it to represent it correctly. (Ex. 0xf63a002c5ff0338ec...
31
2883
by: Sam of California | last post by:
Is it accurate to say that "the preprocessor is just a pass in the parsing of the source file"? I responded to that comment by saying that the preprocessor is not just a pass. It processes...
10
2115
by: abir | last post by:
Hi, This is not strictly a C++ language question. Is there any way to form a string from an identifier with the preprocessor with some operations ? i.e to say to make a string from an...
9
2008
by: Bob | last post by:
Hi, Is it possible to change the references in a project by using preprocessor directives? Thanks, Bob
0
7198
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7271
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
5570
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4998
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3149
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1498
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
373
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.