[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Nano-devel] Now that we really don't need it . . .
From: |
Steven Kneizys |
Subject: |
[Nano-devel] Now that we really don't need it . . . |
Date: |
Fri, 22 Feb 2002 21:52:54 -0800 (PST) |
In the category of "interesting but I wonder if I will ever use it"
here is what seems to be a portable way, with macros, to get the number
of digits in a defined item using stringification:
#include <stdlib.h>
#include <limits.h>
#define my_str_stringification(x) #x
#define get_str_len_of_item(x) (sizeof(my_str_stringification(x))-1)
#define INT_MAX_DIGITS get_str_len_of_item(INT_MAX)
main(){
char buf[INT_MAX_DIGITS];/* not used, but compiles ok with osf */
printf("This is the defined max int: %d\n",INT_MAX);
printf("The number of digits it has: %d\n",INT_MAX_DIGITS);
}
Peeking at gcc intermediate files, the good stuff gets expanded to:
char buf[(sizeof("2147483647" )-1) ];
printf("This is the defined max int: %d\n",2147483647 );
printf("The number of digits it has: %d\n",(sizeof("2147483647" )-1)
);
and the output is:
This is the defined max int: 2147483647
The number of digits it has: 10
take care,
Steve...
__________________________________________________
Do You Yahoo!?
Yahoo! Sports - Coverage of the 2002 Olympic Games
http://sports.yahoo.com
- Re: [Nano-devel] merged patch, (continued)
- Re: [Nano-devel] merged patch, Jordi Mallach, 2002/02/22
- Re: [Nano-devel] merged patch, Jordi Mallach, 2002/02/22
- Re: [Nano-devel] merged patch, Chris Allegretta, 2002/02/22
- Re: [Nano-devel] merged patch, Jordi Mallach, 2002/02/22
- Re: [Nano-devel] merged patch, Jordi Mallach, 2002/02/23
Re: [Nano-devel] merged patch, Steven Kneizys, 2002/02/21
- Re: [Nano-devel] merged patch, Chris Allegretta, 2002/02/21
- Re: [Nano-devel] merged patch, Chris Allegretta, 2002/02/21
- Re: [Nano-devel] merged patch, Dwayne Rightler, 2002/02/22
- Re: [Nano-devel] merged patch, Steven Kneizys, 2002/02/22
- [Nano-devel] Now that we really don't need it . . .,
Steven Kneizys <=
- [Nano-devel] small fix: --enable-tiny;question about: check_statusblank();old stuff, Steven Kneizys, 2002/02/23
- [Nano-devel] 1.1.6 mem leaks revisited, Steven Kneizys, 2002/02/24
- Re: [Nano-devel] 1.1.6 mem leaks revisited, Chris Allegretta, 2002/02/26
Re: [Nano-devel] merged patch, Steven Kneizys, 2002/02/22
Re: [Nano-devel] merged patch, Gareth Pearce, 2002/02/21
Re: [Nano-devel] merged patch, David Lawrence Ramsey, 2002/02/22