<div dir="ltr">Hi,<br><div><br>On Sun, Feb 17, 2013 at 7:02 AM, <a href="mailto:sdptroy3@gmail.com">sdptroy3@gmail.com</a> <<a href="mailto:sdptroy3@gmail.com">sdptroy3@gmail.com</a>> wrote:<br>><br>> hi,<br>> i'm reading the file ioctl.h, there i encountered a macro<br>
> _IOC_TYPECHECK(t) which looks like:<br>> #define _IOC_TYPECHECK(t) \<br>> ((sizeof(t) == sizeof(t[1]) && \<br>> sizeof(t) < (1 << _IOC_SIZEBITS)) ? \<br>> sizeof(t) : __invalid_size_argument_for_IOC)<br>
><br>> in this code ,what does sizeof(t[1]) mean? i mean the argument of this<br>> macro in a type(int, float), in that case what does sizeof(int[1])<br>> specify? I have written a small test program which prints the value of<br>
> the expression 4.<br><br></div><div>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.<br>
<br></div><div>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.<br><br></div><div>Some code erroneously passed in bare ints, which are not types, and they wanted to produce a compiler error in this situation.<br>
</div><div><br>--<br>Dave Hylands<br>Shuswap, BC, Canada<br><a href="http://www.davehylands.com">http://www.davehylands.com</a></div></div>