Re: [OT] C++ question re. dyn. mem.
On Wed, Aug 06, 2003 at 10:36:42AM -0400, MJM wrote:
> On Wednesday 06 August 2003 01:02, Dave Carrigan wrote:
> > > Language experts sure get their shorts knotted up over simple questions.
> > >
> > Because your question had to do with undefined and
> > implementation-dependent behavior.
> I know that. See my other posts. I asked a question about handling dynamic
> memory not type casting. I changed what I was doing to use templates and
> made a container class (probably did it wrong, but I don't care at this
You asked a question about using the delete operator an pointer to an
object that had been cast from a different object. That behavior is
undefined in C++.
> I got dragged over the coals for type casting - something used often in the
Nobody is saying that casts are bad. But, the kernel is written in C.
What happens in C system programming is irrelevant to C++ application
programming. Well designed C++ applications should require significantly
less casting, and most of those will be static_casts, and maybe some
const_casts, and probably never reinterpret_casts, which is what your
example was doing.
To me, it didn't sound like chastisement. However, any good C++
programmer will cringe when they see a C-style cast, and will point it
out. Any learning C++ programmer would do well to take the advice when
it is given. Knowledge of how to use C++ casts hardly falls in the realm
of the "language experts".
> Type casting works in my application on Intel 32bit Linux. Using casts is
> useful in my work with bit oriented telephony signaling protocols where you
> have to count bits and octets because parameter structures in messages are
> dynamic. I am _not_ going to add all sorts of portability enhancing do-dads
> that make C++ even more difficult to read than it already is. If what I make
> is useful and someone wants it on a different platform, then we'll discuss a
> new project.
That's all just great. I'm very happy for you. But, you should change
the sentence to read "type casting works in my application on Intel
32bit Linux when compiled with gcc 3.2 and libstdc++ 3.3". Without
testing, you cannot know that the statement is true for any other
combination of gcc and libstdc++.
If your programs use undefined behavior that rely on a specific version
of a specific vendor's compiler on a specific operating system, your
programs will eventually break and your maintainers will hate you.
> It is unreasonable to expect application experts to be language experts.
I would hardly call it unreasonable. If you don't understand the
language you're using, then how can you expect to write a reliable
> It's good if they are but it's not necessary. I say it's better to create
> more things with bad code than to create less things with elegant and easily
> portable code.
I hear Microsoft is still hiring. It sounds like you would fit right in.
Seattle, WA, USA
email@example.com | http://www.rudedog.org/ | ICQ:161669680