D
David Mathog
c99 introduced (or at least standardized) uint32_t, uint64_t etc., and
that provides a way to write code
so that the size of the variables remains the same on platforms where
int, long, etc. can be different sizes. So far so good. However,
there do not seem to be any corresponding fprintf specifiers, just the
existing l, ll and u. and those do not have a fixed size. So in c99
how does one write this code fragment portably?
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
uint32_t var=1;
fprintf(stdout,"%lu \n",var);
That would work on a 32 bit platform, but %lu could be 8 bytes on a 64
bit platform, rather than the intended 4 bytes.
Thanks,
David Mathog
that provides a way to write code
so that the size of the variables remains the same on platforms where
int, long, etc. can be different sizes. So far so good. However,
there do not seem to be any corresponding fprintf specifiers, just the
existing l, ll and u. and those do not have a fixed size. So in c99
how does one write this code fragment portably?
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
uint32_t var=1;
fprintf(stdout,"%lu \n",var);
That would work on a 32 bit platform, but %lu could be 8 bytes on a 64
bit platform, rather than the intended 4 bytes.
Thanks,
David Mathog