c - What does sizeof(int[1]) mean? -


i new linux kernel. reading file ioctl.h, there encountered macro _ioc_typecheck(t), looks this:

#define _ioc_typecheck(t) \         ((sizeof(t) == sizeof(t[1]) && \           sizeof(t) < (1 << _ioc_sizebits)) ? \           sizeof(t) : __invalid_size_argument_for_ioc) 

can explain me code? in code, sizeof(t[1]) mean?

this used check validity of third parameter _ior/_iow/_iowr macros, supposed type. checks parameter type (and not variable or number), , causes compiler or linker error otherwise.

  • if t type, t[1] type "an array of 1 t". type has same size t, , therefore sizeof(t) == sizeof(t[1]) true.

  • if t number, sizeof(t) fail compile.

  • if t simple (non-array) variable, t[1] cause compiler error.

  • if t array variable, sizeof(t) == sizeof(t[1]) false, , linker error caused (because __invalid_size_argument_for_ioc not defined).

the expression sizeof(t) < (1 << _ioc_sizebits) checks size of type t not exceed maximum allowed ioctl, , causes same linker error otherwise.

there still invalid cases not caught macro - example, when t pointer pointer.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -