What is timer_t in its base?

Gcc and printf

say it timer_t

is a pointer (on mine linux

). But what NULL

does this pointer and the actual timer ID fit in ?

Also, it's a platform specific thing like. g is a pointer to linux

, int to macOs

, sth. else on BSD

.

+4


source to share


2 answers


Are you talking about user space or kernel space? It matters even on one platform. It really boils down to the fact that the implementation of functions that should be treated as opaque.

The function implementation uses timer_t

can use an integer as an offset in an array of data structures, or dynamically allocate standby timer data structures.

This opacity of timer functions means that NULL may be valid on some systems, but not on others.

If you look at the Single Unix Specification for sys/types.h

, you will see that it mentions timer_t

and says "All types are defined as arithmetic types of the appropriate length", but it does not indicate what exactly is stored inside the type (since a pointer is actually just an integer, which turns out to be an address somewhere else in memory).

Linux kernel headers ( int

):



include/linux/types.h:typedef __kernel_timer_t  timer_t;
include/uapi/asm-generic/posix_types.h:typedef int      __kernel_timer_t;

      

Linux glibc sources / headers (pointer void*

):

time/bits/types/timer_t.h:typedef __timer_t timer_t;
bits/types.h:__STD_TYPE __TIMER_T_TYPE __timer_t;
sysdeps/unix/sysv/linux/x86/bits/typesizes.h:#define __TIMER_T_TYPE     void *
sysdeps/unix/sysv/linux/sparc/bits/typesizes.h:#define __TIMER_T_TYPE       void *
sysdeps/unix/sysv/linux/s390/bits/typesizes.h:#define __TIMER_T_TYPE        void *
sysdeps/unix/sysv/linux/generic/bits/typesizes.h:#define __TIMER_T_TYPE     void *
sysdeps/unix/sysv/linux/alpha/bits/typesizes.h:#define __TIMER_T_TYPE       void *
sysdeps/nacl/bits/typesizes.h:#define __TIMER_T_TYPE        void *
sysdeps/mach/hurd/bits/typesizes.h:#define __TIMER_T_TYPE       __S32_TYPE
bits/typesizes.h:#define __TIMER_T_TYPE     void *

      

Solaris Headers (via GCC) ( int

):

#ifndef _TIMER_T
#define _TIMER_T
typedef int timer_t;    /* timer identifier type */  <typedef:timer_t>
#endif  /* ifndef _TIMER_T */

      

+5


source


The problem with how it's done is that it doesn't even define any invalid value, so you can't wrap timer_t without a second variable just to indicate if it was initialized successfully, instead of relying on 0. -1, NULL or just TIMER_T_NONE, for example. Whoever invented this API obviously hasn't approached programming for several years :-(



0


source







All Articles