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)
|