TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: THOMAS HABETS
from: JONATHAN DE BOYNE POLLARD
date: 1998-02-02 09:42:00
subject: converting char to string

 JdBP>>         char ch ;
 JdBP>>         char str[2] = { ch } ;
 TH> Not at initilation time, at runtime
I don't understand your objection.  My only guess is that you aren't familiar 
with this particular part of the C++ language, and are erroneously assuming 
that objects with automatic storage duration are initialised at program 
startup.  They are not.
The semantics of Standard C++ *require* that automatic storage objects be 
initialised every time that execution passes through the statement.  In this 
case, str[] is initialised with the current value of `ch' and a zero.
This idiom is a very useful shorthand for those occasions where otherwise one 
would, as you did, follow an array or structure declaration of automatic 
storage with a succession of assignment statements.
See sections 8.5 and 8.5.1 (especially paragraph 7) of the C++ Standard.
 ¯ JdeBP ®
--- FleetStreet 1.19 NR
---------------
* Origin: JdeBP's point, using Squish (2:440/4.3)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.