<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> &lt;<a href="mailto:sdptroy3@gmail.com">sdptroy3@gmail.com</a>&gt; wrote:<br>&gt;<br>&gt; hi,<br>&gt; i&#39;m reading the file ioctl.h, there i encountered a macro<br>
&gt; _IOC_TYPECHECK(t) which looks like:<br>&gt; #define _IOC_TYPECHECK(t) \<br>&gt;         ((sizeof(t) == sizeof(t[1]) &amp;&amp; \<br>&gt;           sizeof(t) &lt; (1 &lt;&lt; _IOC_SIZEBITS)) ? \<br>&gt;           sizeof(t) : __invalid_size_argument_for_IOC)<br>
&gt;<br>&gt; in this code ,what does sizeof(t[1]) mean? i mean the argument of this<br>&gt; macro in a type(int, float), in that case what does sizeof(int[1])<br>&gt; specify? I have written a small test program which prints the value of<br>
&gt; 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&#39;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>