Hi,
On Sun, Feb 17, 2013 at 7:02 AM, sdptroy3@xxxxxxxxx <sdptroy3@xxxxxxxxx> wrote:
>
> hi,
> i'm reading the file ioctl.h, there i encountered a macro
> _IOC_TYPECHECK(t) which looks like:
> #define _IOC_TYPECHECK(t) \
> ((sizeof(t) == sizeof(t[1]) && \
> sizeof(t) < (1 << _IOC_SIZEBITS)) ? \
> sizeof(t) : __invalid_size_argument_for_IOC)
>
> in this code ,what does sizeof(t[1]) mean? i mean the argument of this
> macro in a type(int, float), in that case what does sizeof(int[1])
> specify? I have written a small test program which prints the value of
> the _expression_ 4.
On Sun, Feb 17, 2013 at 7:02 AM, sdptroy3@xxxxxxxxx <sdptroy3@xxxxxxxxx> wrote:
>
> hi,
> i'm reading the file ioctl.h, there i encountered a macro
> _IOC_TYPECHECK(t) which looks like:
> #define _IOC_TYPECHECK(t) \
> ((sizeof(t) == sizeof(t[1]) && \
> sizeof(t) < (1 << _IOC_SIZEBITS)) ? \
> sizeof(t) : __invalid_size_argument_for_IOC)
>
> in this code ,what does sizeof(t[1]) mean? i mean the argument of this
> macro in a type(int, float), in that case what does sizeof(int[1])
> specify? I have written a small test program which prints the value of
> the _expression_ 4.
So t has to be a type. t[1] is an array of t with a single element (so normally you would use t v[1], but sizeof doesn't need a variable). sizeof(t[1]) returns the size of the array of one element of type t.
If t is not a type, then the _expression_ sizeof(t[1]) will produce a compile error, which is what they were trying to achieve.
Some code erroneously passed in bare ints, which are not types, and they wanted to produce a compiler error in this situation.
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@xxxxxxxxxxxxxxxxx http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies