http://groups.google.com/group/comp.lang.c++?hl=en
comp.lang.c++@googlegroups.com
Today's topics:
* Who gets higher salary a Java Programmer or a C++ Programmer? - 18 messages,
5 authors
http://groups.google.com/group/comp.lang.c++/t/4017272356b778c8?hl=en
* Can this loop be vectorized? - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/cc5c855b5a6dc0c5?hl=en
* How to play with C callbacks (signal()) using C++ instance methods. - 1
messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/c845807decdddaa6?hl=en
* Problems with callback - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/041acc5bc5bcb728?hl=en
* delete [] and NULL - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/9534fe669af9f828?hl=en
* Why no tstring, tcerr, tostringstream, etc - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/91d2abd51ff64925?hl=en
* binary format of the number. - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/bf11dd6e68624537?hl=en
* out of scope pointers in threads - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/1413d3875476ff47?hl=en
==============================================================================
TOPIC: Who gets higher salary a Java Programmer or a C++ Programmer?
http://groups.google.com/group/comp.lang.c++/t/4017272356b778c8?hl=en
==============================================================================
== 1 of 18 ==
Date: Fri, Nov 28 2008 11:11 am
From: LR
Lew wrote:
> Martin Gregorie wrote:
>>> Same here: its well recognised in the UK. I hold a CE in software
>>> engineering as well as an MSc (Chemistry).
>
> Tom Anderson wrote:
>> But i'm right in thinking that one doesn't need either of those to call
>> oneself a software engineer, i hope?
>
> Absolutely.
What is your understanding of the requirements to call yourself a
software engineer?
TIA
LR
== 2 of 18 ==
Date: Fri, Nov 28 2008 11:16 am
From: LR
Martin Gregorie wrote:
> On Wed, 26 Nov 2008 22:36:41 -0500, LR wrote:
>
>> Martin Gregorie wrote:
>>> On Wed, 26 Nov 2008 16:32:19 -0500, LR wrote:
>>>
>>>> But I think I made it plain that engineers don't consider the entire
>>>> physics of the bridge. They might not consider fluid interactions or
>>>> wind loading or some such. The parameters are likely to be driven by
>>>> budget, customer requirements or perhaps good practice.
>>>>
>>> That's quite wrong. The engineers who designed the Tay and the Tacoma
>>> Narrows bridges ignored wind and look where that got them.
>>
>> I'm sorry, but what is quite wrong? I completely fail to understand how
>> your response contradicts anything I wrote above. Please explain,
>> because I utterly bewildered by your response.
>>
> This:
> "But I think I made it plain that engineers don't consider the entire
> physics of the bridge. They might not consider fluid interactions or
> wind loading or some such."
>
> I suggest you do some reading about those bridges.
I have read a bit about them. Sorry, but I really am quite confused now.
You said that they ignored wind loading and I agreed that they might
not consider fluid interactions or wind loading. Perhaps you object to
the redundancy?
Could you please explain to me where we disagree?
LR
== 3 of 18 ==
Date: Fri, Nov 28 2008 11:16 am
From: Tommy
Daniel T. wrote:
> Tommy <plas@dacxsee.com> wrote:
>> Tom Anderson wrote:
>>
>>>> Same here: its well recognised in the UK. I hold a CE in software
>>>> engineering as well as an MSc (Chemistry).
>>> But i'm right in thinking that one doesn't need either of those to call
>>> oneself a software engineer, i hope?
>> A programmer who calls himself a Software Engineer is not going to
>> fool those who know the difference - job wise, need wise, hiring wise,
>> pay wise.
>
> I think many people here have anecdotes to the contrary.
>
> Tom the problem is that many who have CE degrees in "software
> engineering" aren't effective software engineers, and many who are
> effective don't hold a degree. I'm not going to hazard to guess what the
> proportions are, but the question is enough up in the air, that
> requiring a degree for any software construction job would be a huge
> mistake IMHO.
>
> The above may not always be the case, schools may one day become
> effective in weeding out the unqualified and not graduating them, but
> they aren't there yet. I think part of the problem is that no one is
> really sure what software engineering really entails yet.
Possibly, but at the end of the day, considering the topic (who gets a
higher salary among Java, C++), one who attempts to cover the gambit
or believes the better pay will come by self-proclaiming to be a
"Software Engineer" in his resume, better have the credentials and
experience to back it up. A CE degree is nice, but it must also be
coupled with practical experience. When I talking to potential hire,
a good clue that the person has promise is when he tells me he can't
live without his white board. :-)
He would be just as well calling himself a "Software Developer", or
Project Developer or Product Developer.
The former tells me he has R&D experience, design experience. The
latter tells me he has production, QA, customer relations, even
possible technical sales and support experiences.
Grant it, with today smarter tools, IDEs, etc, the many traditional
disciplines have merged. That was the intent - not only to increase
productivity, but to lower the cost of expertise requirements,
increase output without increasing staff. If a developer wants to say
he is Software Engineer because he uses these tools, even created
tools, has experience with all the current languages, he might get
hired, but not a SE pay scale. If he can put start a project from
start to finish, create functional specs, communicate with others to
fine tine it without writing a single line of code, then he/she may
deserve the pay, but then again he probably won't be looking at a
programming position. :-)
Anyway my take. To me, SE still means something and an "IDE" does not
make one an SE.
--
== 4 of 18 ==
Date: Fri, Nov 28 2008 11:20 am
From: LR
Paavo Helde wrote:
[snip]
> So it appears
> that my source code file represents an enormous simplification and
> approximation of the actual computing process taking place on the machine
> at the time my program is run. In other words, I can predict with some
> certainty that my program will work correctly,
Makes the process easier, but doesn't change it fundamentally, because
of it's mathematical nature. It isn't a physical process.
LR
== 5 of 18 ==
Date: Fri, Nov 28 2008 11:20 am
From: Arne Vajhøj
LR wrote:
> Lew wrote:
>> Martin Gregorie wrote:
>>>> Same here: its well recognised in the UK. I hold a CE in software
>>>> engineering as well as an MSc (Chemistry).
>> Tom Anderson wrote:
>>> But i'm right in thinking that one doesn't need either of those to call
>>> oneself a software engineer, i hope?
>> Absolutely.
>
> What is your understanding of the requirements to call yourself a
> software engineer?
In most places it is a job title not an academic title or other
type of certification.
So in most places the requirements is that a company will give
you a job with that title.
Arne
== 6 of 18 ==
Date: Fri, Nov 28 2008 11:26 am
From: Arne Vajhøj
Tim Roberts wrote:
> Arne Vajhøj <arne@vajhoej.dk> wrote:
>> LR wrote:
>>> On business cards? Letterhead? I'm sorry, I don't recall, did you say
>>> you were a PE?
>> Software engineer is a widely used title in the US.
>>
>> Try search on dice.com or monster.com !
>
> The fact that it is widely used does not mean that it is CORRECTLY used.
I am very skeptical about so called "correct" definitions of words
that are different from the way they are used in practice.
Arne
== 7 of 18 ==
Date: Fri, Nov 28 2008 11:28 am
From: LR
Ian Collins wrote:
>>> And to repeat, I once spoke to a EE who told me his company
>>> was going to test software for all possible inputs. Once I did
>>> the arithmetic for him he withdrew his statement.
>
> Just like they test their circuits with all possible inputs!
Heh heh. But that's part of the point isn't it?
Engineers don't do that, because they rely on the physics to make
predictions about how things will work over a range of physical conditions.
I think that's more difficult for programmers who work with what is a
mathematical construct where provability is more of an issue.
LR
== 8 of 18 ==
Date: Fri, Nov 28 2008 11:29 am
From: Arne Vajhøj
LR wrote:
> OTOH, I've never heard of someone actually being prosecuted for calling
> themselves an engineer. I repeat IANAL, but I suspect, but do not know,
> that if you did something that might be considered to be malpractice
> whilst calling yourself an engineer things might get interesting.
If someone design a bridge, it collapses and it turns out he is a
software engineer with degree in computer science, then I am sure
all hell will break out.
But if a software engineer designs a piece of software that crashes
then I can not imagine him being prosecuted for not having an
engineering degree in bridge building.
Arne
== 9 of 18 ==
Date: Fri, Nov 28 2008 11:31 am
From: LR
Tom Anderson wrote:
> On Thu, 27 Nov 2008, Martin Gregorie wrote:
>
>> On Wed, 26 Nov 2008 22:36:41 -0500, LR wrote:
>>
>>> Martin Gregorie wrote:
>>>> On Wed, 26 Nov 2008 16:32:19 -0500, LR wrote:
>>>>
>>>>> But I think I made it plain that engineers don't consider the entire
>>>>> physics of the bridge. They might not consider fluid interactions or
>>>>> wind loading or some such. The parameters are likely to be driven by
>>>>> budget, customer requirements or perhaps good practice.
>>>>>
>>>> That's quite wrong. The engineers who designed the Tay and the Tacoma
>>>> Narrows bridges ignored wind and look where that got them.
>>> I'm sorry, but what is quite wrong? I completely fail to understand how
>>> your response contradicts anything I wrote above. Please explain,
>>> because I utterly bewildered by your response.
>>>
>> This:
>> "But I think I made it plain that engineers don't consider the entire
>> physics of the bridge. They might not consider fluid interactions or
>> wind loading or some such."
>>
>> I suggest you do some reading about those bridges.
>
> Hold up - those examples show that, in the cases of those bridges (or
> Tacoma Narrows, at least), the engineers indeed did not consider wind
> loading!
Maybe you can clear this up then. I think that's what I wrote or at
least implied I think that's what MG wrote above. I honestly don't see
where we have a disagreement.
Confusedly,
LR
== 10 of 18 ==
Date: Fri, Nov 28 2008 11:45 am
From: LR
James Kanze wrote:
> There are similarities, but testing is not an option for all
> disciplines. How do you "test" a skyscraper?
They build mathematical models, with the knowledge that since our
knowledge of the physical world is imperfect the models won't work
perfectly. But these are used to come as close as you can with the
scientific knowledge (law?) available. Then you make some physical
models, maybe full size ones, for testing various kinds of things.
I only know this from reading about it in some book long ago, since
besides not being an engineer, I'm not an architect either. ;)
The model I read about was to test for windows leaking in rainstorms.
I'm not sure if they'd still do that today. Maybe use some CFD code to
check, although more recently, I think Boeing had a bit of a surprise
when an engine they were testing let loose like a flame thrower on
takeoff. The computer models did not predict this. Well, like I said,
our understanding of the physics is imperfect.
There are some other interesting things about building failures
including that they tend to be publicly investigated. Both formally and
informally. People make documentaries about those failures.
Also, I suppose it depends exactly what you are testing the skyscraper
for. I saw a documentary about how the people who study how groups of
people act during catastrophic events, like fires, or earthquakes build
full scale tiltable models of staircases to see how people will move on
them in various stressful situations.
LR
== 11 of 18 ==
Date: Fri, Nov 28 2008 11:47 am
From: LR
Martin Gregorie wrote:
> On Thu, 27 Nov 2008 21:21:01 +0000, Tom Anderson wrote:
>
>> Oh, absolutely. I'm not knocking the value of qualifications! At least,
>> not all of them. I was just wondering if my lack of them made me a
>> criminal.
>>
> Why on earth would it do that?
>
> We're not yet /required/ to belong to a professional association like
> medical doctors.
>
>
Are doctors required to belong to a professional association? May I ask
what jurisdiction you're speaking of.
However, in almost every jurisdiction that I know of where it would
matter, software engineers, actually anyone who calls themselves an
engineer, like doctors, lawyers and hairdressers are required to have a
license.
Am I wrong?
LR
== 12 of 18 ==
Date: Fri, Nov 28 2008 12:03 pm
From: Ian Collins
LR wrote:
>
> When an engineer designs a bridge, they may for example try to figure
> out how the bridge will react to a given load. They may try this for
> various loads. The load limit is determined by physics.
>
> What is the analogous thing for software?
>
The Roman or medieval bridge builder who pre-dated the discovery of physics?
The Roman or medieval bridge builder was no less of an engineer than
today's bridge builder. If anything he was more of an engineer because
he didn't have machines to do his donkey work for him.
The physics of software has not been discovered yet, so we still have to
rely in basic engineering and scientific principals to build our
applications. Maybe every software application has its own set of
physical laws?
--
Ian Collins
== 13 of 18 ==
Date: Fri, Nov 28 2008 12:08 pm
From: Ian Collins
LR wrote:
>
> However, in almost every jurisdiction that I know of where it would
> matter, software engineers, actually anyone who calls themselves an
> engineer, like doctors, lawyers and hairdressers are required to have a
> license.
>
> Am I wrong?
>
Yes.
--
Ian Collins
== 14 of 18 ==
Date: Fri, Nov 28 2008 12:11 pm
From: Tom Anderson
On Thu, 27 Nov 2008, Arne Vajhøj wrote:
> LR wrote:
>> James Kanze wrote:
>>
>>>> I was wondering if you could take a shot at answering what I think is
>>>> a simple question with what might be a quick answer: What scientific
>>>> principle is being applied in "software engineering"?
>>>
>>> Mathematics.
>>
>> Yeah, that's it then. Except math is not a science.
>
> Sure is.
>
> It is a formal science and a basis for all the empirical sciences.
I don't consider mathematics a science. The foundation of science is
experiment: you do experiments, and from the results, you draw conclusions
about the world. Mathematics does not have experiments. In mathematics,
you start with some assumptions, and then you use pure logic to work out
as many conclusions as you can. The kind of knowledge you get from the two
systems is really very different - they're called a posteriori and a
priori, respectively.
However, it doesn't follow that mathematics cannot be the basis of
software engineering. Rather, given that software is a purely mathematical
thing, which doesn't have physical existence [1], it's pretty obvious that
mathematics is the *only* thing which could be the basis of software
engineering.
tom
[1] Really, it doesn't! There are physical realisations of software which
have material existence, but they aren't software themselves. It's like
the distinction between a story and a book. You wouldn't argue that the
making of stories is based on the science of papermaking, would you?
--
Would you like to remember more?
== 15 of 18 ==
Date: Fri, Nov 28 2008 12:13 pm
From: LR
Martin Gregorie wrote:
> On Thu, 27 Nov 2008 21:13:44 +0000, Tom Anderson wrote:
>
>> On Thu, 27 Nov 2008, Martin Gregorie wrote:
>>
>>> On Wed, 26 Nov 2008 22:36:41 -0500, LR wrote:
>>>
>>>> Martin Gregorie wrote:
>>>>> On Wed, 26 Nov 2008 16:32:19 -0500, LR wrote:
>>>>>
>>>>>> But I think I made it plain that engineers don't consider the entire
>>>>>> physics of the bridge. They might not consider fluid interactions or
>>>>>> wind loading or some such. The parameters are likely to be driven
>>>>>> by budget, customer requirements or perhaps good practice.
>>>>>>
>>>>> That's quite wrong. The engineers who designed the Tay and the Tacoma
>>>>> Narrows bridges ignored wind and look where that got them.
>>>> I'm sorry, but what is quite wrong? I completely fail to understand
>>>> how your response contradicts anything I wrote above. Please explain,
>>>> because I utterly bewildered by your response.
>>>>
>>> This:
>>> "But I think I made it plain that engineers don't consider the entire
>>> physics of the bridge. They might not consider fluid interactions or
>>> wind loading or some such."
>>>
>>> I suggest you do some reading about those bridges.
>> Hold up - those examples show that, in the cases of those bridges (or
>> Tacoma Narrows, at least), the engineers indeed did not consider wind
>> loading!
>>
> Exactly so. Look back up this post and you'll see that "LR" said it
> didn't matter whether bridge designers looked at wind loading or not
> because the cost of doing the design was a bigger consideration than
> spending time and money to calculate wind loading.
I don't think that I said that exactly.
Or perhaps you're jumping to the conclusion that I think this is a good
thing.
The fact remains, engineers do not always, or maybe ever, consider the
full physics of whatever they are designing. No one has either an
unlimited amount of money, or a perfect understanding of the physical
world, although this can be mitigated by good practice.
> I pointed to two well-
> known failures that were due to the designers ignoring wing factors. He
> evidently *didn't know* that both blew down because he clearly didn't
> understand that reply.
I think that you're mistaken about this. In any case, it would be
peculiar if someone didn't know that Tacoma was a result of a fluids
problem. I went back and reread what I wrote about the Tay, and I did
say that I thought it might have collapsed under it's own weight and I
agree with you that I was mistaken in that fact.
> You jumped in when I was trying, rather politely I thought, to give "LR"
> the chance to dig himself out of his self-constructed hole rather than
> calling him a pig-headed know-nothing. So I won't, but I did want to see
> what his reply would be.
I have already responded. I was utterly bewildered by your previous
response and now, if it were possible, I would be even more so.
I think that I'll stand by what I wrote, with the exception of the cause
of the Tay's failure. Since I am still not sure what you understood from
what I posted, please feel free to ask me to amplify or clarify and I
will be happy to make the attempt. Otherwise, I shall be glad to wallow
quite contentedly in my hole.
LR
== 16 of 18 ==
Date: Fri, Nov 28 2008 12:17 pm
From: LR
Arne Vajhøj wrote:
> LR wrote:
>> courpron@gmail.com wrote:
>>> On 26 nov, 02:00, LR <lr...@superlink.net> wrote:
>>>> courp...@gmail.com wrote:
>>>>> On 25 nov, 15:38, LR <lr...@superlink.net> wrote:
>>>>>> {...]
>>>>>> Do the programs provably work? To the same extent that an engineer could
>>>>>> "prove" that the bridge they designed will work?
>>>>> There is a whole branch of computer science that is dedicated to
>>>>> "program provability". In the practical world, the theory gave rise to
>>>>> what is called "design by contract", by which you define formally the
>>>>> specifications of your program with pre/postconditions, invariants,
>>>>> etc. You can mathematically prove that your program will work by those
>>>>> means. This is used in any sensible environment that needs absolutely
>>>>> reliable softwares.
>>>> Absolutely reliable? Suppose you have a customer who wants a formal
>>>> proof that the program you've written will halt. Can you provide that?
>>> Yes, absolutely reliable. The program is proven to be correct in any
>>> way. The proof can be given in the form of mathematical notations.
>> I'm not sure you responded to my question, so please allow me to restate
>> it. Suppose you have a customer who wants a formal proof that the
>> program you've written will halt, can you provide that?
>
> Most likely yes.
>
> Computer science has proven that it is not possible to do that
> for all programs, but it can be done for some programs. If one
> is willing to spend the money, then it can be done for most
> programs.
>
> (the examples used to prove the haling problem is not
> generally solvable are not very realistic programs)
What is the relevance of their being realistic programs or not?
LR
== 17 of 18 ==
Date: Fri, Nov 28 2008 12:18 pm
From: LR
Arne Vajhøj wrote:
> LR wrote:
>> Lew wrote:
>>> LR wrote:
>>>> Tom Anderson wrote:
>>>>
>>>>> Still, i call myself a 'software engineer' because it sounds more
>>>>> high-status than 'programmer', and i go to a lot of parties with lawyers
>>>>> and academics and the like.
>>>> IANAL, but since you're calling yourself a "software engineer" might I
>>>> ask what jurisdiction you do that in?
>>> I call myself a "software engineer" in Maryland, the U.S. of A.
>>>
>> On business cards? Letterhead? I'm sorry, I don't recall, did you say
>> you were a PE?
>
> Software engineer is a widely used title in the US.
>
> Try search on dice.com or monster.com !
At one time, or so I was told in school, many people believed the world
was flat. It did not make it so.
LR
== 18 of 18 ==
Date: Fri, Nov 28 2008 12:20 pm
From: LR
Arne Vajhøj wrote:
> LR wrote:
>> James Kanze wrote:
>>> For some types of
>>> software, at laest. For real time software, it's less obvious,
>>> since it's fairly hard to be sure that you've analysed all
>>> possible timing issues.
>> I don't think testing all the possible interactions is possible for most
>> software. Consider a fairly simple program that reads inputs for say 64
>> boolean variables and has at least one conditional branch for each
>> variable.
>
> >> But it's still several orders of
> >> magnitude easier than verifying that you've analysed all
> >> possible physical interactions which might affect a bridge.
> >
> > But that isn't done. AFAIK ever. I don't think there's enough time in
> > the universe to do that. Not even for all the likely cases.
>
> That is a very unscientific and non-engineering way of
> thinking.
What about this way of thinking is unscientific or non-engineering. Do
>
> It can be done is most cases. It will not be done in most cases
> for cost reasons.
Time isn't a factor?
>
>>>> I was wondering if you
>>>> could take a shot at answering what I think is a simple
>>>> question with what might be a quick answer: What scientific
>>>> principle is being applied in "software engineering"?
>>> Mathematics.
>> Yeah, that's it then. Except math is not a science.
>
> Sure is.
>
> It is a formal science and a basis for all the empirical
> sciences.
Certainly not what I was taught in school.
LR
==============================================================================
TOPIC: Can this loop be vectorized?
http://groups.google.com/group/comp.lang.c++/t/cc5c855b5a6dc0c5?hl=en
==============================================================================
== 1 of 1 ==
Date: Fri, Nov 28 2008 11:22 am
From: red floyd
دريد عبد الله wrote:
> Sory For Mistake
> Tyy To Type:
>
> double a[N], b[N];
> int c[2N];
>
> for(int i=0; i<N; i++) {
> tmp = c[i*2]; // All now are integers
> a[i] = b[tmp];
>
> }
> Please try this..
> But for knowing
> I tryed your code on turbo c++ 4.5 . It was running..
>
That wasn't what OP was asking. To the OP, you're better off asking in
a group dedicated to your compiler -- ISO/IEC 14882:2003 doesn't discuss
vectorization at all.
==============================================================================
TOPIC: How to play with C callbacks (signal()) using C++ instance methods.
http://groups.google.com/group/comp.lang.c++/t/c845807decdddaa6?hl=en
==============================================================================
== 1 of 1 ==
Date: Fri, Nov 28 2008 11:25 am
From: James Kanze
On Nov 28, 3:48 pm, Maxim Yegorushkin <maxim.yegorush...@gmail.com>
wrote:
> On Nov 28, 2:25 pm, James Kanze <james.ka...@gmail.com> wrote:
> > On Nov 28, 10:42 am, Maxim Yegorushkin
> > <maxim.yegorush...@gmail.com> wrote:
> > > On Nov 28, 8:32 am, James Kanze <james.ka...@gmail.com> wrote:
> > [...]
> > > C and C++ calling conventions have been the same on
> > > Solaris. I don't think Sun will ever change it because
> > > their remaining customers are not going to be happy.
> > > While formally it might make sense to emit this error, it
> > > is practically useless.
> > It's required by the standard. A compiler which doesn't emit
> > the error isn't conform. The fact that the calling conventions
> > happen to be the same isn't really relevant; the language allows
> > them to be different, and considers them different types.
> Is there a platform/compiler where they are different?
There certainly have been; there are very strong reasons for
making them different on an Intel, for example, and they were
different on the first C++ compiler I used. (I'm not too sure
what the situation is with VC++ today; I think it uses some
non-standard means, but the results are the same.)
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
==============================================================================
TOPIC: Problems with callback
http://groups.google.com/group/comp.lang.c++/t/041acc5bc5bcb728?hl=en
==============================================================================
== 1 of 1 ==
Date: Fri, Nov 28 2008 11:34 am
From: James Kanze
On Nov 27, 11:49 pm, Juha Nieminen <nos...@thanks.invalid> wrote:
> maverik wrote:
> > Question: is there a way in that i can do this (can register
> > class method as a callback):
> > m_listView.SetMouseButtonUpCb(&MyClass::DoClick);
> A member function can not be called using a function pointer
> only for the simple reason that a member function *always*
> needs an object as well. (Basically you can think that a
> pointer to the object is always passed to the member function
> as the first parameter. Which is usually actually the case
> internally with most compilers.)
> If the callback mechanism only supports taking a function
> pointer and nothing else, then it obviously cannot call a
> member function because it has no object pointer to give.
Back in the good old days, people used static variables (and
"good" is meant very, very ironically).
> Most callback function mechanisms support taking some user
> data, usually in the form of a void*. What you do is that you
> give a pointer to the object as this void*, and then use a
> regular callback function which receives that void*. That
> callback function then just reinterpret-casts the void* to the
> type of the class and uses it to call the member function.
First, it's static_cast you want, not reinterpret_cast. And
second, you have to be very, very careful; the static_cast must
be to exactly the type which served to get the void*. So, for
example, something like:
extern "C" void callback( void* p )
{
static_cast< Base* >( p )->doSomething() ;
}
// ...
Derived theObject ;
registerCallback( &callback, &theObject ) ;
is undefined behavior (supposing registerCallback takes a void*
as second argument). You must do:
registerCallback( &callback,
static_cast< Base* >( &theObject ) ) ;
> If you are writing the callback mechanism yourself, then you
> can automatize this to great lengths using templates, but it's
> a bit complicated.
Particularly if the interface requires an ``extern "C"''
function (which is usually the case).
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
==============================================================================
TOPIC: delete [] and NULL
http://groups.google.com/group/comp.lang.c++/t/9534fe669af9f828?hl=en
==============================================================================
== 1 of 1 ==
Date: Fri, Nov 28 2008 11:37 am
From: Hendrik Schober
Pete Becker wrote:
> On 2008-11-25 05:05:35 -0500, Lars Uffmann <aral@nurfuerspam.de> said:
>
>> dmparadiselm wrote:
>>> It is guaranteed that a NULL pointer deletion is harmless in C++
>>> standard.
>> @OP: However, as dmparadiselm pointed out, you really want to set your
>> pointers to NULL after deletion, for a
>> delete p;
>> might (will) wreak havoc on your program if p is not NULL but there is
>> no memory reserved anymore.
>>
>
> But setting every deleted pointer to 0 doesn't solve real problems.
But it might hide real problems.
> [...]
Schobi
==============================================================================
TOPIC: Why no tstring, tcerr, tostringstream, etc
http://groups.google.com/group/comp.lang.c++/t/91d2abd51ff64925?hl=en
==============================================================================
== 1 of 1 ==
Date: Fri, Nov 28 2008 11:39 am
From: Hendrik Schober
James Kanze wrote:
> On Nov 28, 12:44 pm, Hendrik Schober <spamt...@gmx.de> wrote:
>> James Kanze wrote:
>>> On Nov 28, 12:05 am, Paavo Helde <pa...@nospam.please.ee> wrote:
>>> [...]
>
>>>> If you are coding for Windows only, then the wise thing
>>>> (which does not mean I'm actually recommending it!) would
>>>> be to use their TCHAR and friends, they most probably will
>>>> remain back-compatible to some extent.
>
>>> The problem is that they promote a lie; the give the
>>> impression that you can easily switch to and from Unicode,
>>> just by changing a typedef.
>
>> I've done this, although not using 'TCHAR', and across
>> several platforms. What makes this impossible IYO?
>
> The fact that the way the encodings work is different.
Um, I guess the confusion stems from your "just by changing
a typedef". Of course, there's a lot more required than just
changing a typedef, but it can be done so that just changing
a typedef does all this. I suppose you referred to the former
(it needs more), while I referred to the latter (it can be
done so that changing a typedef does everything that needs to
be done).
Schobi
==============================================================================
TOPIC: binary format of the number.
http://groups.google.com/group/comp.lang.c++/t/bf11dd6e68624537?hl=en
==============================================================================
== 1 of 1 ==
Date: Fri, Nov 28 2008 11:40 am
From: Hendrik Schober
J.W. wrote:
> In c++, we can use hex format to represent a number, for example, for number
> 70, we can use 0x46, but is there a way to represent a number using the
> binary format, something similar to 0x.
ISTR that boost has some template that yields an integer
const from a string of o and 1. ICBWT.
> J.W.
Schobi
==============================================================================
TOPIC: out of scope pointers in threads
http://groups.google.com/group/comp.lang.c++/t/1413d3875476ff47?hl=en
==============================================================================
== 1 of 1 ==
Date: Fri, Nov 28 2008 11:47 am
From: James Kanze
uche wrote:
> I am trying to send a pointer to the thread below; however,
> when the thread gets executed, the pointer goes out of scope .
> How do I fix it ?
What is "data"? Is it a data type, or a pointer to a data type?
You seem to use it both ways.
> int mywrite(char* id, int number_of_characters, char char_array)
> {
> HANDLE Producer;
> DWORD ThId;
> //global_char = char_array;
> //create mutual exlusion for producer process to write into the buffer
> //create producer thread and start the function for inserting characters
> //mywriteTh is the entry point of the producer
> ptr =new data;
OK, we have 'data' as a data type, and 'ptr' is, I suppose a
data*.
> ptr->character = char_array;
Again, what is char_array? Where does it come from?
> cout<<ptr->character<<endl;
> ptr->id = id;
> cout<<ptr->id<<endl;
> Producer = (HANDLE) CreateThread (NULL, 0, mywriteTh,
> reinterpret_cast<data> (ptr) , 0, &ThId); // i want to send the
> pointer to this thread
Anytime you need a reinterpret_cast for a function argument, you
should be asking yourself questions. If I understand the
interface description of CreateThread at MSDN (Microsoft seems
to go in a lot for obfuscated typenames), you don't need any
cast at all; just pass the pointer. (I'm guessing here that
LPVOID is a void*; where the L comes from, I don't know.)
> cout<<ptr->id<<endl;
> return 0;
> }
> DWORD WINAPI mywriteTh(data ptr)
And according to the documentation, this function must take a
void* (well, an LPVOID) as well, not a data. (The documentation
shows some __in as well. More obfuscation; I don't think it
means anything.)
> {
> //global_char is available here
> DWORD tId = GetCurrentThreadId();
> data *ptr_data = reinterpret_cast<data *>(ptr); // pointer is goes
> out of scope
Again, a reinterpret_cast is a no-no. You need a static_cast of
the void* to the exact type of the pointer that was converted to
void*, above.
> }
As for "going out of scope", of course the pointer goes out of
scope. But you're passing a copy of it to the thread, and the
memory it points to is still there.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
==============================================================================
You received this message because you are subscribed to the Google Groups "comp.lang.c++"
group.
To post to this group, visit http://groups.google.com/group/comp.lang.c++?hl=en
To unsubscribe from this group, send email to comp.lang.c+++unsubscribe@googlegroups.com
To change the way you get mail from this group, visit:
http://groups.google.com/group/comp.lang.c++/subscribe?hl=en
To report abuse, send email explaining the problem to abuse@googlegroups.com
==============================================================================
Google Groups: http://groups.google.com/?hl=en
No comments:
Post a Comment