www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/12/01/11:51:46

Message-ID: <DB85AFBE7C0DD311BF260004ACB80BFCECD1@nex_server.nextransport.com>
From: George Kinney <GKinney AT nextransport DOT com>
To: "'djgpp AT delorie DOT com'" <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)
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 <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
Content-Type: text/html
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3DUS-ASCII">
<META NAME=3D"Generator" CONTENT=3D"MS Exchange Server version =
5.5.2448.0">
<TITLE>Re: sizeof() but nothing to do with sizeof( some_structure =
)</TITLE>
</HEAD>
<BODY>
<BR>

<P><FONT COLOR=3D"#0000FF" SIZE=3D2 FACE=3D"Arial">&gt;</FONT><FONT =
SIZE=3D2 FACE=3D"Arial">Yep, sizeof() is a built in operator...</FONT>
</P>

<P><FONT COLOR=3D"#0000FF" SIZE=3D2 FACE=3D"Arial">&gt;</FONT><FONT =
SIZE=3D2 FACE=3D"Arial">AFAIK, it's converted straight into a typeless =
token, ie if it's printf (&quot;%i&quot;,</FONT>
<BR><FONT COLOR=3D"#0000FF" SIZE=3D2 FACE=3D"Arial">&gt;</FONT><FONT =
SIZE=3D2 FACE=3D"Arial">sizeof(int)); it will be parsed to =
printf(&quot;%i&quot;, 4); and then that number will</FONT>
<BR><FONT COLOR=3D"#0000FF" SIZE=3D2 FACE=3D"Arial">&gt;</FONT><FONT =
SIZE=3D2 FACE=3D"Arial">be converted to the appropriate type (in this =
case integer)...</FONT>
</P>

<P><FONT COLOR=3D"#0000FF" SIZE=3D2 FACE=3D"Arial">Technically, it =
returns a value of type size_t, but size_t itself is defined </FONT>
<BR><FONT COLOR=3D"#0000FF" SIZE=3D2 FACE=3D"Arial">as an unsigned int, =
so saying it returns int is ok.</FONT>
</P>

<P><FONT COLOR=3D"#0000FF" SIZE=3D2 FACE=3D"Arial">Relevant bit of the =
C standard: (6.5.3.4 The sizeof operator)</FONT>
</P>

<P><FONT COLOR=3D"#0000FF" SIZE=3D2 =
FACE=3D"Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Constraints</FONT>
</P>

<P><FONT COLOR=3D"#0000FF" SIZE=3D2 =
FACE=3D"Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [#1]&nbsp; =
The&nbsp; sizeof&nbsp; operator&nbsp; shall&nbsp; not&nbsp; be&nbsp; =
applied&nbsp; to&nbsp; an</FONT>
<BR><FONT COLOR=3D"#0000FF" SIZE=3D2 =
FACE=3D"Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; expression&nbsp; =
that has function type or an incomplete type, to</FONT>
<BR><FONT COLOR=3D"#0000FF" SIZE=3D2 =
FACE=3D"Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; the parenthesized =
name of such a type, or to&nbsp; an&nbsp; expression |</FONT>
<BR><FONT COLOR=3D"#0000FF" SIZE=3D2 =
FACE=3D"Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; that designates a =
bit-field member.</FONT>
</P>

<P><FONT COLOR=3D"#0000FF" SIZE=3D2 =
FACE=3D"Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Semantics</FONT>
</P>

<P><FONT COLOR=3D"#0000FF" SIZE=3D2 =
FACE=3D"Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [#2]&nbsp; =
The&nbsp; sizeof operator yields the size (in bytes) of its</FONT>
<BR><FONT COLOR=3D"#0000FF" SIZE=3D2 =
FACE=3D"Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; operand, which may =
be an&nbsp; expression&nbsp; or&nbsp; the&nbsp; parenthesized</FONT>
<BR><FONT COLOR=3D"#0000FF" SIZE=3D2 =
FACE=3D"Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; name of a =
type.&nbsp; The size is determined from the type of the</FONT>
<BR><FONT COLOR=3D"#0000FF" SIZE=3D2 =
FACE=3D"Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; operand.&nbsp; The =
result is an integer.&nbsp;&nbsp; If&nbsp; the&nbsp; type&nbsp; =
of&nbsp; the</FONT>
<BR><FONT COLOR=3D"#0000FF" SIZE=3D2 =
FACE=3D"Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; operand&nbsp; =
is&nbsp; a&nbsp; variable&nbsp; length&nbsp; array type, the operand =
is</FONT>
<BR><FONT COLOR=3D"#0000FF" SIZE=3D2 =
FACE=3D"Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; evaluated; =
otherwise, the operand is not evaluated&nbsp; and&nbsp; the</FONT>
<BR><FONT COLOR=3D"#0000FF" SIZE=3D2 =
FACE=3D"Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; result is an =
integer constant.</FONT>
</P>

<P><FONT COLOR=3D"#0000FF" SIZE=3D2 =
FACE=3D"Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [#3] When applied =
to an operand that has type char, unsigned</FONT>
<BR><FONT COLOR=3D"#0000FF" SIZE=3D2 =
FACE=3D"Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; char, or signed =
char, (or a qualified version&nbsp; thereof)&nbsp; the</FONT>
<BR><FONT COLOR=3D"#0000FF" SIZE=3D2 =
FACE=3D"Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; result&nbsp; =
is&nbsp; 1.&nbsp;&nbsp; When&nbsp; applied&nbsp; to an operand that has =
array</FONT>
<BR><FONT COLOR=3D"#0000FF" SIZE=3D2 =
FACE=3D"Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; type, the =
result&nbsp; is&nbsp; the&nbsp; total&nbsp; number&nbsp; of&nbsp; =
bytes&nbsp; in&nbsp; the</FONT>
<BR><FONT COLOR=3D"#0000FF" SIZE=3D2 FACE=3D"Arial">&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp; array.75)&nbsp;&nbsp; When applied to an operand that =
has structure or</FONT>
<BR><FONT COLOR=3D"#0000FF" SIZE=3D2 =
FACE=3D"Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; union type, the =
result is the total number of bytes in&nbsp; such</FONT>
<BR><FONT COLOR=3D"#0000FF" SIZE=3D2 =
FACE=3D"Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; an object, =
including internal and trailing padding.</FONT>
</P>

<P><FONT COLOR=3D"#0000FF" SIZE=3D2 =
FACE=3D"Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [#4]&nbsp; The =
value of the result is implementation-defined, and</FONT>
<BR><FONT COLOR=3D"#0000FF" SIZE=3D2 =
FACE=3D"Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; its type (an =
unsigned integer type) is&nbsp; size_t,&nbsp; defined&nbsp; in</FONT>
<BR><FONT COLOR=3D"#0000FF" SIZE=3D2 =
FACE=3D"Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; the =
&lt;stddef.h&gt; header.</FONT>
</P>

<P><FONT COLOR=3D"#0000FF" SIZE=3D2 =
FACE=3D"Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 75)When&nbsp; =
applied&nbsp; to&nbsp; a&nbsp; parameter declared to have array =
or</FONT>
<BR><FONT COLOR=3D"#0000FF" SIZE=3D2 =
FACE=3D"Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
function type, the sizeof operator yields the size of the</FONT>
<BR><FONT COLOR=3D"#0000FF" SIZE=3D2 =
FACE=3D"Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
adjusted (pointer) type (see 6.9.1).</FONT>
</P>
<BR>

</BODY>
</HTML>
------_=_NextPart_001_01BF3C08.38A40E06--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019