linux - [Solved-5 Solutions] What is ultimately a time_t typedef to ? - ubuntu - red hat - debian - linux server - linux pc



Linux - Problem :

What is ultimately a time_t typedef to ?

Linux - Solution 1:

  • The time_t datatype is a data type in the ISO C library defined for storing system time values.
  • Such values are returned from the standard time() library function.
  • This type is a typedef defined in the standard header.
  • ISO C defines time_t as an arithmetic type, but does not specify any particular type, range, resolution, or encoding for it.
  • Also unspecified are the meanings of arithmetic operations applied to time values.
  • Unix and POSIX-compliant systems implement the time_t type as a signed integer which represents the number of seconds since the start of the Unix epoch

Linux - Solution 2:

[root]# cat time.c
click below button to copy the code. By - Linux tutorial - team
#include <time.h>

int main(int argc, char** argv)
{
        time_t test;
        return 0;
}
click below button to copy the code. By - Linux tutorial - team
[root]# gcc -E time.c | grep __time_t
click below button to copy the code. By - Linux tutorial - team
typedef long int __time_t;
click below button to copy the code. By - Linux tutorial - team

It's defined in $INCDIR/bits/types.h

# 131 "/usr/include/bits/types.h" 3 4
# 1 "/usr/include/bits/typesizes.h" 1 3 4
# 132 "/usr/include/bits/types.h" 2 3 4
click below button to copy the code. By - Linux tutorial - team

Linux - Solution 3:

  • Typically you will find these underlying implementation-specific typedefs for gcc in the bits or asm header directory.
  • For Example: /usr/include/x86_64-linux-gnu/bits/types.h

Linux - Solution 4:

Under Visual Studio 2008, it defaults to an __int64 unless you define _USE_32BIT_TIME_T.

Linux - Solution 5:

time_t is of type long int on 64 bit machines, else it is long long int.

You could verify this in these header files:

time.h: /usr/include
types.h and typesizes.h: /usr/include/x86_64-linux-gnu/bit
click below button to copy the code. By - Linux tutorial - team

1)In time.h

typedef __time_t time_t;
click below button to copy the code. By - Linux tutorial - team

2)In types.h

# define __STD_TYPE     typedef  
__STD_TYPE __TIME_T_TYPE __time_t;  
click below button to copy the code. By - Linux tutorial - team

3)In typesizes.h

#define __TIME_T_TYPE       __SYSCALL_SLONG_TYPE  
#if defined __x86_64__ && defined __ILP32__  
# define __SYSCALL_SLONG_TYPE   __SQUAD_TYPE  
#else
# define __SYSCALL_SLONG_TYPE   __SLONGWORD_TYPE
#endif  
click below button to copy the code. By - Linux tutorial - team

4) Again in types.h

#define __SLONGWORD_TYPE    long int
#if __WORDSIZE == 32
# define __SQUAD_TYPE       __quad_t
#elif __WORDSIZE == 64
# define __SQUAD_TYPE       long int  

#if __WORDSIZE == 64
typedef long int __quad_t;  
#else
__extension__ typedef long long int __quad_t;
click below button to copy the code. By - Linux tutorial - team

Related Searches to - linux - linux tutorial - What is ultimately a time_t typedef to