Mail Archives: djgpp/1997/07/24/12:27:44
You wrote:
>Chirayu Krishnappa wrote:
>>
>> >However, all is not lost. There is a very useful header file
>> >defined in the ANSI standard which contains things about the sizes
>> >of variables. It's called limits.h. Among the things it defines
>>
>> Thanks! I'm using this approach now.
>
>The only problem with it is that it's clumsy and in CS terms "not elegant".
>I would really like some 'elegant' code to do it - as it is, I go with what
>works...
I have seen programs which attempt to be ultraportable work by creating
their own definitions before compiling. Example:
- Have a file sizes.c that goes:
#include <stdio.h>
int main(void)
{
if (sizeof(long) == 4)
{
printf("#define LONGSIZE 4\n");
printf("typedef long int32\n");
}
/* And so on... */
}
- Then, in your makefile:
sizes : sizes.c
gcc -o sizes sizes.c
sizes.h : sizes
sizes >sizes.h
- And have everything that needs the sizes #include sizes.h, and put the
appropriate dependencies in the makefile.
You can take care of many machine dependencies this way. I've seen it done
for endian-ness as well.
HTH
Nate Eldredge
eldredge AT ap DOT net
- Raw text -