TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: NEIL HELLER
from: DARIN MCBRIDE
date: 1998-05-02 12:00:00
subject: OPINIONS?

 NH> Given the following code snippet:
 NH> char     *   m_recid = "for whom the bell tolls";
 NH> CString  *   abc = m_recid;
Given this, I'd say it shouldn't even compile.  CString is not derived from 
char, nor is char derived from CString, thus the pointers are incompatable.
CString abc = m_recid; // there is a constructor for CString that takes char*
Not that I'm fond of where you're putting the *'s, but that's a stylistic 
issue, I'll try to stick to pure technical issues.  :-)
 NH> if (*m_recid == NULL) {
Why are you comparing a char to a pointer?  It works simply because NULL in 
C++ is 0, not (void*)0.
 NH> I'd be interested to hear others' opinions.  One person said this was
 NH> the worst example of coding he'd ever seen (I didn't say it and I
 NH> didn't write it).
It is not the worst I've seen, but it's getting close.  Two problems in three 
lines is not a good average.
 NH> BTW, this brings up a couple points of interest to me.  Is abc above a
 NH> pointer to a pointer to char (in addition to being a pointer to a
 NH> CString object)?  Does the following code:
abc above is broken - your compiler shouldn't accept the code.
 NH> char   *   abc[20];
 NH> automatically instantiate a pointer to a pointer to the first element
 NH> of abc?
No - abc is a pointer to an array of pointers.
abc -> [ptr0 | ptr1 | ptr2 | ... ]
You thus have just allocated (on the stack), 20 * sizeof(char*) bytes.  The 
pointers, obviously, behave as any other stack-based pointers - they're 
uninitialized.
---
---------------
* Origin: Tanktalus' Tower BBS (1:250/102)

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™.