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

 JdBP>>>>         char str[2] = { ch } ;
 TH>>> Not at initilation time, at runtime
 JdBP>> I don't understand your objection.
 TH> I have a (good IMO) habit of declaring all my variables that will be
 TH> used in the entire function in the beginning. Just like C [...]
So ?  The value of `ch' used is the value that it has at the time of the 
declaration of `str'.  I still don't understand your objection, unless it is: 
"I don't use the ability of C++ to declare variables close to the point of 
first use rather than at the block start, therefore I have prevented myself 
arbitrarily from making use of the feature of the C++ language employed in 
the example above, therefore the example above is wrong.".  
 JdBP>> My only guess is that you aren't familiar with this particular part
 JdBP>> of the C++ language,
 TH> No, this one time I am correct! Dammit! :-)
I'm afraid you aren't.  The above code works, and does the job.  Just because 
you have decided to restrict yourself to declaring variables at the start of 
blocks and nowhere else, doesn't make the language feature wrong.  
Incidentally, in my experience as a professional programmer I have maintained 
C++ code written in C form with exactly such self-imposed coding style 
restrictions as you are applying to yourself, and far too often it has turned 
out to be the cause of subtle initialisation and scope bugs, which converting 
to the C++ style of declaring a variable as close to the point of first use 
as possible quickly eliminated, or at least highlighted.  So I certainly 
wouldn't recommend your chosen coding style.  It makes a C++ maintenance 
programmer's job a lot harder.
 ¯ 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™.