China Blue Veins
4/1/2011 9:59:00 AM
In article <9a31982f-0eac-4444-9769-5dd02718c397@32g2000vbe.googlegroups.com>,
pozz <pozzugno@gmail.com> wrote:
> So I'm wondering if it could be better to use new C99 types, such as
> int32_t. In this case, on 32-bit platform with 64-bit long, I'll use
> the simple int for my variable...
That's what they're there for--to explicitly state the sizes when you need to
explicitly set the sizes. And if your platform doesn't include stdint.h, make
your own.
For build tools like make it's pretty easy to create the header file and then
include it.
program: int.h program.c
...
int.h:
echo >int.c '#include <stdio.h>'
echo >>int.c '#include <limits.h>'
echo >>int.c 'int main(int n,char **p) {'
echo >>int.c 'char *i8 = 0,*i16 = 0,*i32 = 0,*i64 = 0;'
echo >>int.c '#ifdef SCHAR_MAX'
echo >>int.c 'if (SCHAR_MAX==0x7F) *i8 = "char";'
echo >>int.c 'else if (SCHAR_MAX==0x7FFF) *i16 = "char";'
echo >>int.c 'else if (SCHAR_MAX==0x7FFFFFFF) *i32 = "char";'
echo >>int.c 'else if (SCHAR_MAX==0x7FFFFFFFFFFFFFFF) *i64 = "char";'
echo >>int.c '#endif'
echo >>int.c '#ifdef SHRT_MAX'
echo >>int.c 'if (SHRT_MAX==0x7F) *i8 = "short";'
echo >>int.c 'else if (SHRT_MAX==0x7FFF) *i16 = "short";'
echo >>int.c 'else if (SHRT_MAX==0x7FFFFFFF) *i32 = "short";'
echo >>int.c 'else if (SHRT_MAX==0x7FFFFFFFFFFFFFFF) *i64 = "short";'
echo >>int.c '#endif'
echo >>int.c '#ifdef INT_MAX'
echo >>int.c 'if (INT_MAX ==0x7F) *i8 = "int";'
echo >>int.c 'else if (INT_MAX==0x7FFF) *i16 = "int";'
echo >>int.c 'else if (INT_MAX==0x7FFFFFFF) *i32 = "int";'
echo >>int.c 'else if (INT_MAX==0x7FFFFFFFFFFFFFFF) *i64 = "int";'
echo >>int.c '#endif'
echo >>int.c '#ifdef LONG_MAX'
echo >>int.c 'if (LONG_MAX==0x7F) *i8 = "long";'
echo >>int.c 'else if (LONG_MAX==0x7FFF) *i16 = "long";'
echo >>int.c 'else if (LONG_MAX==0x7FFFFFFF) *i32 = "long";'
echo >>int.c 'else if (LONG_MAX==0x7FFFFFFFFFFFFFFF) *i64 = "long";'
echo >>int.c '#endif'
echo >>int.c '#ifdef LONG_LONG_MAX'
echo >>int.c 'if (LONG_LONG_MAX ==0x7F) *i8 = "long long";'
echo >>int.c 'else if (LONG_LONG_MAX==0x7FFF) *i16 = "long long";'
echo >>int.c 'else if (LONG_LONG_MAX==0x7FFFFFFF) *i32 = "long long";'
echo >>int.c 'else if (LONG_LONG_MAX==0x7FFFFFFFFFFFFFFF)'
echo >>int.c ' *i64 = "long long";'
echo >>int.c '#endif'
echo >>int.c 'if (!i64) i64 = "long long";'
echo >>int.c 'if (!i32) i32 = i64;'
echo >>int.c 'if (!i16) i16 = i32;'
echo >>int.c 'if (!i8) i8 = i16;'
echo >>int.c 'printf("#ifndef int_h"); puts("");'
echo >>int.c 'printf("#define int_h"; puts("");'
echo >>int.c 'printf("typedef signed %s int8_t;", i8); puts("");'
echo >>int.c 'printf("typedef signed %s int16_t;", i16); puts("");'
echo >>int.c 'printf("typedef signed %s int32_t;", i32); puts("");'
echo >>int.c 'printf("typedef signed %s int64_t;", i64); puts("");'
echo >>int.c 'printf("typedef unsigned %s uint8_t;", i8); puts("");'
echo >>int.c 'printf("typedef unsigned %s uint16_t;", i16); puts("");'
echo >>int.c 'printf("typedef unsigned %s uint32_t;", i32); puts("");'
echo >>int.c 'printf("typedef unsigned %s uint64_t;", i64); puts("");'
echo >>int.c 'printf("#endif"); puts("");'
echo >>int.c 'return 0;}'
cc -o int int.c
int >int.h
--
Damn the living - It's a lovely life. I'm whoever you want me to be.
Silver silverware - Where is the love? At least I can stay in character.
Oval swimming pool - Where is the love? Annoying Usenet one post at a time.
Damn the living - It's a lovely life. Alameda County Sheriff.