Topic: Question of declarations/type casts....


Author: "me" <frgthmthr@hotmail.com>
Date: Fri, 8 Feb 2002 02:25:11 GMT
Raw View
This is a multi-part message in MIME format.

------=_NextPart_000_002A_01C1B004.FDC83A00
Content-Type: text/plain;
 charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

One of my text books uses the expression

    type (expression);

extensively. One of the most common uses is for tests and checks of type =
bool.

    bool isok;
    isok =3D bool ( 1 =3D=3D 1);

Can someone please point out a place in the standard that specifies =
exactly what this syntax does?  I've gotten answers including a new C++ =
style type cast, and the declaration and initialization of an unnamed =
variable.  Thank you much for any feedback

Mike Schroder
Fullerton JC

------=_NextPart_000_002A_01C1B004.FDC83A00
Content-Type: text/html;
 charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2712.300" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>One of my text books uses the=20
expression</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; =
<STRONG>type</STRONG>=20
(expression);</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>extensively. One of the most common =
uses is for=20
tests and checks of type bool.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; =
<STRONG>bool</STRONG>=20
isok;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; isok<EM> =3D=20
</EM><STRONG>bool</STRONG> ( 1 =3D=3D 1);</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Can someone please point out a place in =
the=20
standard that specifies exactly what this syntax does?&nbsp; I've gotten =
answers=20
including a new C++ style type cast, and the declaration and =
initialization of=20
an unnamed variable.&nbsp; Thank you much for any feedback</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Mike Schroder</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Fullerton JC</FONT></DIV></BODY></HTML>

------=_NextPart_000_002A_01C1B004.FDC83A00--

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]





Author: "James Kuyper Jr." <kuyper@wizard.net>
Date: Fri, 8 Feb 2002 03:53:31 GMT
Raw View
> me wrote:
>
> One of my text books uses the expression
>
>     type (expression);
>
> extensively. One of the most common uses is for tests and checks of
> type bool.
>
>     bool isok;
>     isok = bool ( 1 == 1);
>
> Can someone please point out a place in the standard that specifies
> exactly what this syntax does?  I've gotten answers including a new
> C++ style type cast, and the declaration and initialization of an
> unnamed variable.  Thank you much for any feedback

It's basically an alternate syntax for the old C style cast. It's
described in section 5.2.3:

"Explicit type conversion (functional notation)
A _simple-type-specifier_ (7.1.5) followed by a parenthesized
_expression-list_ constructs a value of the specified type given the
expression list. If the expression list is a single expression, the type
conversion operation is equivalent (in definedness, and if defined, in
meaning) to the corresponding cast expression."


In other words, type(expression) is equivalent to (type)expression. This
only works for a _simple-type-specifier_, which is defined in 7.1.5.2:
 ::opt _nested-name-specifier_opt _type-name_
 ::opt _nested-name-specifier_ template _template-id_
 char
 wchar_t
 bool
 short
 int
 long
 signed
 unsigned
 float
 double
 void

It does not work for type specifier sequences, such as 'long int'.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]





Author: Francis Glassborow <francis.glassborow@ntlworld.com>
Date: Fri, 8 Feb 2002 17:45:35 GMT
Raw View
In article <OE35wGdYumcI3mS3T4d000123c0@hotmail.com>, me=20
<frgthmthr@hotmail.com> writes
>One of my text books uses the expression
>=A0
>=A0=A0=A0 type (expression);
>=A0
>extensively. One of the most common uses is for tests and checks of=20
>type bool.
>=A0
>=A0=A0=A0 bool isok;
>=A0=A0=A0 isok =3D bool ( 1 =3D=3D 1);
>=A0
>Can someone please point out a place in the standard that specifies=20
>exactly what this syntax does?=A0 I've gotten answers including a new C+=
+=20
>style type cast, and the declaration and initialization of an unnamed=20
>variable.=A0 Thank you much for any feedback
Try 5.2.3 explicit type conversion.

--=20
Francis Glassborow
Check out the ACCU Spring Conference 2002
4 Days, 4 tracks, 4+ languages, World class speakers
For details see: http://www.accu.org/events/public/accu0204.htm

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]





Author: Francis Glassborow <francis.glassborow@ntlworld.com>
Date: Fri, 8 Feb 2002 17:45:41 GMT
Raw View
In article <3C634A3C.1A0BAA59@wizard.net>, James Kuyper Jr.
<kuyper@wizard.net> writes
>It does not work for type specifier sequences, such as 'long int'.

Well, it does if you alias them with a typedef:

typedef long int longint;
int a = 0;
long int b = 0;
b = long int (a); // ERROR
b = (long int) a; // OK
b = longint (a); //OK


--
Francis Glassborow
Check out the ACCU Spring Conference 2002
4 Days, 4 tracks, 4+ languages, World class speakers
For details see: http://www.accu.org/events/public/accu0204.htm

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]





Author: "James Kuyper Jr." <kuyper@wizard.net>
Date: Sat, 9 Feb 2002 02:41:08 GMT
Raw View
Francis Glassborow wrote:
>
> In article <3C634A3C.1A0BAA59@wizard.net>, James Kuyper Jr.
> <kuyper@wizard.net> writes
> >It does not work for type specifier sequences, such as 'long int'.
>
> Well, it does if you alias them with a typedef:
>
> typedef long int longint;
> int a = 0;
> long int b = 0;
> b = long int (a); // ERROR
> b = (long int) a; // OK
> b = longint (a); //OK

Correct, since a typdef is a _type-name_, and as such qualifies as a
_simple-type-specifier_.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]