Hi, On Sun, Feb 17, 2013 at 7:02 AM, sdptroy3@gmail.com <sdptroy3@gmail.com> 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. -- Dave Hylands Shuswap, BC, Canada http://www.davehylands.com