nano-devel
[Top][All Lists]
Advanced

[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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]