Gcc and printf
says that timer_t
is pointer (on my linux
). But what is placed by this pointer, and is NULL
a valid timer id?
Also, is it platform-specific thing, e. g. it is pointer on linux
, int on macOs
, sth. else on BSD
.
Gcc and printf
says that timer_t
is pointer (on my linux
). But what is placed by this pointer, and is NULL
a valid timer id?
Also, is it platform-specific thing, e. g. it is pointer on linux
, int on macOs
, sth. else on BSD
.
Are you talking about userspace or kernelspace? It makes a difference even on a single platform. Really it comes down to what the implementation of the functions, which SHOULD be considered as opaque.
The implementation of the functions uses timer_t
might use an integer as an offset into an array of data structures, or dynamically allocates the backing timer data structures.
That opaque-ness of the timer functions means that NULL might be valid in some systems but not others.
If you look at the Single Unix Specification for sys/types.h
, you'll see while it mentions timer_t
, and says "All of the types are defined as arithmetic types of an appropriate length", but doesn't specify what exactly is stored inside the type (since a pointer is really just an integer that happens to be the address of 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 (void*
pointer):
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 */
© 2022 - 2024 — McMap. All rights reserved.