sizeof(struct timeval)
Tony Houghton
this.address.is.fake at realh.co.uk
Mon Mar 13 20:44:47 EST 2006
In <DcmdnRkLxJg4gYvZRVnyrw at pipex.net>,
Big and Blue <No_4 at dsl.pipex.com> wrote:
> Tony Houghton wrote:
>>
>> How safe would I be assuming that
>>
>> sizeof(struct timeval) == 2 * sizeof(long)
>>
>> is always true on Linux on different architectures?
>
> Based on what I was looking at today (well, yesterday now), you might
> be wrong.
>
> I do know that the size of a struct utmp differs between a Linux
> Itanium system and a Linux x86_64 system, and I seem to recall it migh be
> related to timeval. I could be wrong - I wasn't interested in the timeval
> part - but this part of the bits/utmp.h include file indicates the issue:
So is __WORDSIZE_COMPAT32 defined for one of Itanium or x86_64 but not
the other? The comment in the code below implies the opposite of what
you're saying: the size in 64-bit mode has to be the same as in 32-bit
mode, and as both CPUs have the same 32-bit architecture they should
therefore both use the same sized struct in 64-bit mode.
In any case, it does imply that timeval can be relied on to be 2 *
32-bits (2 * long) in 32-bit architectures and something else in 64-bit
architectures - where long is 64-bit.
> /* The ut_session and ut_tv fields must be the same size when compiled
> 32- and 64-bit. This allows data files and shared memory to be
> shared between 32- and 64-bit applications. */
> #if __WORDSIZE == 64 && defined __WORDSIZE_COMPAT32
> int32_t ut_session; /* Session ID, used for windowing. */
> struct
> {
> int32_t tv_sec; /* Seconds. */
> int32_t tv_usec; /* Microseconds. */
> } ut_tv; /* Time entry was made. */
> #else
> long int ut_session; /* Session ID, used for windowing. */
> struct timeval ut_tv; /* Time entry was made. */
> #endif
--
The address in the Reply-To is genuine and should not be edited.
See <http://www.realh.co.uk/contact.html> for more reliable contact addresses.
More information about the Python-list
mailing list