Message-ID: From: George Kinney To: "'djgpp AT delorie DOT com'" Subject: Re: sizeof() but nothing to do with sizeof( some_structure ) Date: Wed, 1 Dec 1999 09:27:33 -0500 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2448.0) Content-Type: multipart/alternative; boundary="----_=_NextPart_001_01BF3C08.38A40E06" Reply-To: djgpp AT delorie DOT com This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. ------_=_NextPart_001_01BF3C08.38A40E06 Content-Type: text/plain >Yep, sizeof() is a built in operator... >AFAIK, it's converted straight into a typeless token, ie if it's printf ("%i", >sizeof(int)); it will be parsed to printf("%i", 4); and then that number will >be converted to the appropriate type (in this case integer)... Technically, it returns a value of type size_t, but size_t itself is defined as an unsigned int, so saying it returns int is ok. Relevant bit of the C standard: (6.5.3.4 The sizeof operator) Constraints [#1] The sizeof operator shall not be applied to an expression that has function type or an incomplete type, to the parenthesized name of such a type, or to an expression | that designates a bit-field member. Semantics [#2] The sizeof operator yields the size (in bytes) of its operand, which may be an expression or the parenthesized name of a type. The size is determined from the type of the operand. The result is an integer. If the type of the operand is a variable length array type, the operand is evaluated; otherwise, the operand is not evaluated and the result is an integer constant. [#3] When applied to an operand that has type char, unsigned char, or signed char, (or a qualified version thereof) the result is 1. When applied to an operand that has array type, the result is the total number of bytes in the array.75) When applied to an operand that has structure or union type, the result is the total number of bytes in such an object, including internal and trailing padding. [#4] The value of the result is implementation-defined, and its type (an unsigned integer type) is size_t, defined in the header. 75)When applied to a parameter declared to have array or function type, the sizeof operator yields the size of the adjusted (pointer) type (see 6.9.1). ------_=_NextPart_001_01BF3C08.38A40E06 Content-Type: text/html Content-Transfer-Encoding: quoted-printable Re: sizeof() but nothing to do with sizeof( some_structure = )

>Yep, sizeof() is a built in operator...

>AFAIK, it's converted straight into a typeless = token, ie if it's printf ("%i",
>sizeof(int)); it will be parsed to = printf("%i", 4); and then that number will
>be converted to the appropriate type (in this = case integer)...

Technically, it = returns a value of type size_t, but size_t itself is defined
as an unsigned int, = so saying it returns int is ok.

Relevant bit of the = C standard: (6.5.3.4 The sizeof operator)

       Constraints

       [#1]  = The  sizeof  operator  shall  not  be  = applied  to  an
       expression  = that has function type or an incomplete type, to
       the parenthesized = name of such a type, or to  an  expression |
       that designates a = bit-field member.

       Semantics

       [#2]  = The  sizeof operator yields the size (in bytes) of its
       operand, which may = be an  expression  or  the  parenthesized
       name of a = type.  The size is determined from the type of the
       operand.  The = result is an integer.   If  the  type  = of  the
       operand  = is  a  variable  length  array type, the operand = is
       evaluated; = otherwise, the operand is not evaluated  and  the
       result is an = integer constant.

       [#3] When applied = to an operand that has type char, unsigned
       char, or signed = char, (or a qualified version  thereof)  the
       result  = is  1.   When  applied  to an operand that has = array
       type, the = result  is  the  total  number  of  = bytes  in  the
   &n= bsp;   array.75)   When applied to an operand that = has structure or
       union type, the = result is the total number of bytes in  such
       an object, = including internal and trailing padding.

       [#4]  The = value of the result is implementation-defined, and
       its type (an = unsigned integer type) is  size_t,  defined  in
       the = <stddef.h> header.

       75)When  = applied  to  a  parameter declared to have array = or
          = function type, the sizeof operator yields the size of the
          = adjusted (pointer) type (see 6.9.1).


------_=_NextPart_001_01BF3C08.38A40E06--