wrote:
> I have problem with the code only with 64 bit big endian machine.
> i have a member size_t val1 in my structure. The size of size_t is
> 32(unsigned int) in 32 bit machines and 64(unsigned long) in 64 bit
> machines.
>
> I am passing address of this variable to a different function (where it
> accepts only pointer to unsigned int) unsigned int *. Basically passing
> a unsigned long pointer instead of unsigned int pointer. I think the
> value is getting truncated while dereferencing int *. In this case how
> do I make my code portable? Can functions like htonl/ntohl will help?
> or casting could be of any help?
>
> Thanks,
> Suresh
Do the circumstances allow the following?
struct {
size_t val1;
} my_struct;
int tmp = 0;
some_function_that_takes_a_pointer_to_an_int(&tmp) ;
if (tmp < 0) /* do something */ ;
my_struct.val1 = tmp;
I assume some_function_that_takes_a_pointer_to_an_int() will be
dereferencing the pointer passed to it later. In this case you still
have some options, but it depends on how you are going to be using the
structure.
Charlie