Re: data exchange between two windows
From: Joseph M. Newcomer (newcomer_at_flounder.com)
Date: 05/24/04
- Next message: Scott McPhillips [MVP]: "Re: spin a thread to listen to a com port"
- Previous message: steve_at_tropheus.demon.co.uk: "Re: Out of date"
- In reply to: Yasoo: "Re: data exchange between two windows"
- Next in thread: Scott McPhillips [MVP]: "Re: data exchange between two windows"
- Reply: Scott McPhillips [MVP]: "Re: data exchange between two windows"
- Reply: Yasoo: "Re: data exchange between two windows"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 24 May 2004 17:15:41 -0400
>From your previous post:
>What is the connection between using malloc, adding a CString, and seeing a bizarre failure?
If you understood constructors, the answer would be obvious. So I can only conclude that
you don't understand them.
Why would you "never use a CString as a member of a struct"? That's just silly. A CString,
CArray, std::vector, std::string, etc. are all completely legitimate data types, and there
is no reason to ever disallow them. Remember, a struct is just a class with implicitly
public members. So choosing a sytnax does not invalidate the use of anything, including
methods of a struct, constructors of a struct, etc. This is legitimate:
typedef struct whatever {
whatever() { x = 0; y = 0; }
int x;
int y;
void transpose() { int t = x; x = y; y = t; }
} whatever;
So what have I missed about C++ syntax that makes it illegal, or even questionable, to use
a struct in this way?
"paying attention" is the whole point of this. If you use 'new', you do NOT need to 'pay
attention'. If you use 'malloc', you MUST pay attention. Any elementary book on
programming methodology will tell you that introducing gratuitous dependencies that
require "paying attention" to unrelated incidentals is incredibly poor style, and
represents high-risk development path.
I tend to get frustrated when the obvious is ignored. I find it hard to justify for ANY
reason that a bad style should be used, encouraged, or even tolerated. I end up getting
programs like this to fix, and I get quite tired of correcting the same blunders when I
could be using my clients' money to do constructive enhancements to their code (which is
what they want anyway, and what they are presumably paying me for). The sort of
foolishness that suggests that malloc of a structure in a C++ program makes sense is quite
amateurish, and I don't mind saying so. SOMEONE has to tell people when they are screwing
up, and the earlier the better.
The problem is that you are confusing the C language with the C++ language. Things like
malloc, free, strcpy, strcat, fixed-length arrays, global variables fulfilling the role of
parameters, and other out-of-date techniques that applied to the C language on a PDP-11
are downright harmful when using C++. And the reference material for a compiler, whether
it is from Microsoft, Sun, AT&T, etc. is not a good way to learn style. You learn style by
reading good code, and by reading good books and articles on how to program. NONE of the
good style information is presented in the reference material, nor should you expect it to
be presented there.
Books such as Stroustrup's book on C++ ARE important, or Lakos' book on large-scale C++
design, because they tell you how to assemble these primitives into real systems.
Read my essay on Brick Science on my MVP Tips site. But it is one thing to pick up bad
habits, and another to defend them in spite of many people telling you that it is a Bad
Idea (I'm not the only one who said that using malloc is a fundamentally bad idea).
joe
On Mon, 24 May 2004 09:21:03 -0700, "Yasoo" <anonymous@discussions.microsoft.com> wrote:
>Well,
>
> It can't be clear that I don't understand constructors, because I do. So I guess you are unclear. I didn't understand the specific example of what you were talking about and needed to see an example of why it would fail. Now that I see what you are talking about a CString as a member of a struct, I see what you are talking about. However, I would never use a CString as a member of a struct and use malloc in this combination (I might consider a pointer to a CString...). So I still don't see anything wrong or irresponsibe with using malloc if you are paying attention to what you are doing.
>
>Joe, your rhetoric in about 80% of your posts is borderline insulting. Not one to get instulted, I don't much care. I suppose I would prefer someone more personable, but I'll take what I can get. As long as you are giving your opinion about my statements... it's clear to me that you are a crude individual. You're rhetoric isn't condusive to friendly conversation. It's just plain terrible. Even still, I do appreciate your time and help in this forum.
>
>I'm not sure how you guys are learning this information. I bought Visual C++ 6.0 from Microsoft and I have spent a lot of time reading the docs. It may appear in the docs, but I never saw anything telling me the do's and don'ts of malloc. Something so critical and so common to inexperienced users, yet it's not apparent from the docs.
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
- Next message: Scott McPhillips [MVP]: "Re: spin a thread to listen to a com port"
- Previous message: steve_at_tropheus.demon.co.uk: "Re: Out of date"
- In reply to: Yasoo: "Re: data exchange between two windows"
- Next in thread: Scott McPhillips [MVP]: "Re: data exchange between two windows"
- Reply: Scott McPhillips [MVP]: "Re: data exchange between two windows"
- Reply: Yasoo: "Re: data exchange between two windows"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|