Mail Archives: djgpp/1999/12/01/11:51:46
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">></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">></FONT><FONT =
SIZE=3D2 FACE=3D"Arial">AFAIK, it's converted straight into a typeless =
token, ie if it's printf ("%i",</FONT>
<BR><FONT COLOR=3D"#0000FF" SIZE=3D2 FACE=3D"Arial">></FONT><FONT =
SIZE=3D2 FACE=3D"Arial">sizeof(int)); it will be parsed to =
printf("%i", 4); and then that number will</FONT>
<BR><FONT COLOR=3D"#0000FF" SIZE=3D2 FACE=3D"Arial">></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"> Constraints</FONT>
</P>
<P><FONT COLOR=3D"#0000FF" SIZE=3D2 =
FACE=3D"Arial"> [#1] =
The sizeof operator shall not be =
applied to an</FONT>
<BR><FONT COLOR=3D"#0000FF" SIZE=3D2 =
FACE=3D"Arial"> expression =
that has function type or an incomplete type, to</FONT>
<BR><FONT COLOR=3D"#0000FF" SIZE=3D2 =
FACE=3D"Arial"> the parenthesized =
name of such a type, or to an expression |</FONT>
<BR><FONT COLOR=3D"#0000FF" SIZE=3D2 =
FACE=3D"Arial"> that designates a =
bit-field member.</FONT>
</P>
<P><FONT COLOR=3D"#0000FF" SIZE=3D2 =
FACE=3D"Arial"> Semantics</FONT>
</P>
<P><FONT COLOR=3D"#0000FF" SIZE=3D2 =
FACE=3D"Arial"> [#2] =
The sizeof operator yields the size (in bytes) of its</FONT>
<BR><FONT COLOR=3D"#0000FF" SIZE=3D2 =
FACE=3D"Arial"> operand, which may =
be an expression or the parenthesized</FONT>
<BR><FONT COLOR=3D"#0000FF" SIZE=3D2 =
FACE=3D"Arial"> name of a =
type. The size is determined from the type of the</FONT>
<BR><FONT COLOR=3D"#0000FF" SIZE=3D2 =
FACE=3D"Arial"> operand. The =
result is an integer. If the type =
of the</FONT>
<BR><FONT COLOR=3D"#0000FF" SIZE=3D2 =
FACE=3D"Arial"> operand =
is a variable length array type, the operand =
is</FONT>
<BR><FONT COLOR=3D"#0000FF" SIZE=3D2 =
FACE=3D"Arial"> evaluated; =
otherwise, the operand is not evaluated and the</FONT>
<BR><FONT COLOR=3D"#0000FF" SIZE=3D2 =
FACE=3D"Arial"> result is an =
integer constant.</FONT>
</P>
<P><FONT COLOR=3D"#0000FF" SIZE=3D2 =
FACE=3D"Arial"> [#3] When applied =
to an operand that has type char, unsigned</FONT>
<BR><FONT COLOR=3D"#0000FF" SIZE=3D2 =
FACE=3D"Arial"> char, or signed =
char, (or a qualified version thereof) the</FONT>
<BR><FONT COLOR=3D"#0000FF" SIZE=3D2 =
FACE=3D"Arial"> result =
is 1. When applied to an operand that has =
array</FONT>
<BR><FONT COLOR=3D"#0000FF" SIZE=3D2 =
FACE=3D"Arial"> type, the =
result is the total number of =
bytes in the</FONT>
<BR><FONT COLOR=3D"#0000FF" SIZE=3D2 FACE=3D"Arial"> &n=
bsp; array.75) When applied to an operand that =
has structure or</FONT>
<BR><FONT COLOR=3D"#0000FF" SIZE=3D2 =
FACE=3D"Arial"> union type, the =
result is the total number of bytes in such</FONT>
<BR><FONT COLOR=3D"#0000FF" SIZE=3D2 =
FACE=3D"Arial"> an object, =
including internal and trailing padding.</FONT>
</P>
<P><FONT COLOR=3D"#0000FF" SIZE=3D2 =
FACE=3D"Arial"> [#4] The =
value of the result is implementation-defined, and</FONT>
<BR><FONT COLOR=3D"#0000FF" SIZE=3D2 =
FACE=3D"Arial"> its type (an =
unsigned integer type) is size_t, defined in</FONT>
<BR><FONT COLOR=3D"#0000FF" SIZE=3D2 =
FACE=3D"Arial"> the =
<stddef.h> header.</FONT>
</P>
<P><FONT COLOR=3D"#0000FF" SIZE=3D2 =
FACE=3D"Arial"> 75)When =
applied to a parameter declared to have array =
or</FONT>
<BR><FONT COLOR=3D"#0000FF" SIZE=3D2 =
FACE=3D"Arial"> =
function type, the sizeof operator yields the size of the</FONT>
<BR><FONT COLOR=3D"#0000FF" SIZE=3D2 =
FACE=3D"Arial"> =
adjusted (pointer) type (see 6.9.1).</FONT>
</P>
<BR>
</BODY>
</HTML>
------_=_NextPart_001_01BF3C08.38A40E06--
- Raw text -