Re: sizeof(int[1]) means what ?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.

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
_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@xxxxxxxxxxxxxxxxx
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux