Monday, February 8, 2010

comp.lang.c++ - 25 new messages in 6 topics - digest

comp.lang.c++
http://groups.google.com/group/comp.lang.c++?hl=en

comp.lang.c++@googlegroups.com

Today's topics:

* Motivation of software professionals - 16 messages, 9 authors
http://groups.google.com/group/comp.lang.c++/t/21a3fdec4dd53e6a?hl=en
* C++ and shared objects - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/c0dc99feb20c6b5f?hl=en
* B const * array[ ] in gobal - 2 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/539f80e07ceb283b?hl=en
* int (*&)() - 4 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/889d2547688e2155?hl=en
* Never seen this usage before - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/9a99c229e104389e?hl=en
* Classes named CFoo (was Re: Odd Exception Behavior) - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/ce3a580936f3cddd?hl=en

==============================================================================
TOPIC: Motivation of software professionals
http://groups.google.com/group/comp.lang.c++/t/21a3fdec4dd53e6a?hl=en
==============================================================================

== 1 of 16 ==
Date: Mon, Feb 8 2010 10:32 am
From: Ian Collins


Malcolm McLean wrote:
> On Feb 8, 1:43 am, James Kanze <james.ka...@gmail.com> wrote:
>> On Feb 5, 3:14 pm, Patricia Shanahan <p...@acm.org> wrote:
>>
>> [...]
>>
>>> That said, by definition professionals are, to some extent, in
>>> it for the money. If they were not, they would be amateurs as
>>> I am now. How that is balanced against interesting work,
>>> physical working conditions, status, etc. varies.
>> I'm not sure if the word "professional" has the same conotations
>> in English as it does in French, but from the French meaning, I
>> don't think you can be truely a "professional" if you're only in
>> it for the money. "Professional" implies being paid for what
>> you do, but it also implies a certain degree of personal
>> standards with regards to quality and such---a "professional"
>> will take pride in his work.
>>
> Strictly a "professional" is someone who is a member of a professional
> body which regulates itself and has the right to control entry to the
> profession.

In some contexts maybe, but golf and cricket clubs had their
"professional" long before anyone thought of developing software. It
isn't the term "professional" that has been bastardised, it's "Engineer".

--
Ian Collins


== 2 of 16 ==
Date: Mon, Feb 8 2010 10:34 am
From: Dirk Bruere at NeoPax


Malcolm McLean wrote:
> On Feb 8, 1:43 am, James Kanze <james.ka...@gmail.com> wrote:
>> On Feb 5, 3:14 pm, Patricia Shanahan <p...@acm.org> wrote:
>>
>> [...]
>>
>>> That said, by definition professionals are, to some extent, in
>>> it for the money. If they were not, they would be amateurs as
>>> I am now. How that is balanced against interesting work,
>>> physical working conditions, status, etc. varies.
>> I'm not sure if the word "professional" has the same conotations
>> in English as it does in French, but from the French meaning, I
>> don't think you can be truely a "professional" if you're only in
>> it for the money. "Professional" implies being paid for what
>> you do, but it also implies a certain degree of personal
>> standards with regards to quality and such---a "professional"
>> will take pride in his work.
>>
> Strictly a "professional" is someone who is a member of a professional
> body which regulates itself and has the right to control entry to the
> profession. For instnace I can't simply buy scalpels and antiseptic
> and set myself up as a brain surgeon - I have to go throguh the
> British Medical Association before they'll let me chop people up. the
> same is true for lawyers, accountants, and some other more obscure
> niches.
>
> Most people aren't professionals, and the word has become misused to
> mean 'skilled workers with high standards'. Bascially employers want
> the advantages of professional status without conferring on their
> employees the control that is the natural concomitant.
>
> Computer programmers are rarely professionals in the true sense, but
> ususally professional in the bastardised sense of the term.

Come to Britain where we have "boffins" or occasionally "eggheads" and
where the gas company will send round an engineer to fix your appliance.
Or, if he cannot manage it, a technician (yes - that's what they really
said).

--
Dirk

http://www.transcendence.me.uk/ - Transcendence UK
http://www.theconsensus.org/ - A UK political party
http://www.blogtalkradio.com/onetribe - Occult Talk Show


== 3 of 16 ==
Date: Mon, Feb 8 2010 10:46 am
From: Seebs


On 2010-02-08, Dirk Bruere at NeoPax <dirk.bruere@gmail.com> wrote:
> Some places you go, however, you never want to return.
> They are real tech sweatshop hellholes with everyone looking for a new
> job. Last place like that I was at the boss said: "This project is
> behind schedule and if it is not on time heads will roll. I am now off
> on holiday". I suspect he returned to an empty office.

I should hope so!

Last time we had a thing behind schedule, the management sent out a request
that we put in extra time to bring it on schedule. They had already cut
product specs in a few key places to try to make things better, and they
told us they'd make it good if we helped them out. We had very close to
24/7 management coverage, and they helped out as much as they could. And
yes, we made the deadline, and they rewarded us suitably.

The primary motivation there wasn't the money, it was the visible
demonstration that the management felt it was their problem more than ours
that the schedule had been wrong. (Note the emphasis; it was not that we
were behind the schedule, it was that the schedule was, empirically, wrong.)

-s
--
Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam@seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!


== 4 of 16 ==
Date: Mon, Feb 8 2010 11:57 am
From: Dirk Bruere at NeoPax


Seebs wrote:
> On 2010-02-08, Dirk Bruere at NeoPax <dirk.bruere@gmail.com> wrote:
>> Some places you go, however, you never want to return.
>> They are real tech sweatshop hellholes with everyone looking for a new
>> job. Last place like that I was at the boss said: "This project is
>> behind schedule and if it is not on time heads will roll. I am now off
>> on holiday". I suspect he returned to an empty office.
>
> I should hope so!
>
> Last time we had a thing behind schedule, the management sent out a request
> that we put in extra time to bring it on schedule. They had already cut
> product specs in a few key places to try to make things better, and they
> told us they'd make it good if we helped them out. We had very close to
> 24/7 management coverage, and they helped out as much as they could. And
> yes, we made the deadline, and they rewarded us suitably.
>
> The primary motivation there wasn't the money, it was the visible
> demonstration that the management felt it was their problem more than ours
> that the schedule had been wrong. (Note the emphasis; it was not that we
> were behind the schedule, it was that the schedule was, empirically, wrong.)
>
> -s

The best place I ever worked was in a small R&D dept run like a
skunkworks. We reported directly to the owner and all other layers of
management eliminated. The most productive place in over 30 years of
design. All went to shit when the owner was persuaded to get in "real"
management. 3 years and the company went from $30m to bust.

--
Dirk

http://www.transcendence.me.uk/ - Transcendence UK
http://www.theconsensus.org/ - A UK political party
http://www.blogtalkradio.com/onetribe - Occult Talk Show


== 5 of 16 ==
Date: Mon, Feb 8 2010 12:06 pm
From: Andy Champ


James Kanze wrote:
>
> I'm not sure if the word "professional" has the same conotations
> in English as it does in French, but from the French meaning, I
> don't think you can be truely a "professional" if you're only in
> it for the money. "Professional" implies being paid for what
> you do, but it also implies a certain degree of personal
> standards with regards to quality and such---a "professional"
> will take pride in his work.
>
I think that side of the meaning is becoming less visible.

There was a time when being an engineer was an important thing - and
what we do is a branch of engineering.

http://upload.wikimedia.org/wikipedia/commons/6/65/Royal_Albert_Bridge_-_Saltash_pier_from_Tamar_Bridge.JPG

AKA

http://preview.tinyurl.com/ykycpgu

Nowadays an engineer is no longer someone who exercises their ingenuity,
but a locomotive driver (US) or repairman.

As time has gone by the status of engineering in general has dropped,
and I think the status of the professions in general. A bank manager
was a professional, but not likely to be particularly qualified; an
accountant definitely counted. The real money these days is made by
arbitrageurs and such who are only professional in the sense that they
are in it for the money. I suspect that most people do not have the
respect for them that a banker, lawyer, politician or doctor would have
attracted in years gone by.

Anyway - money a motivator? Only up to a point, for most people. If
you've got enough it just stops mattering.

Except to those few for whom having lots of money is an end to itself.
And in general they tend not to be technical people.

The other side of the coin is amateur - doing it for the love of it.
And I for one am glad that there are people on this group helping people
for no financial reward whatsoever.

Andy


== 6 of 16 ==
Date: Mon, Feb 8 2010 12:11 pm
From: Tim Streater


On 08/02/2010 20:06, Andy Champ wrote:

> http://preview.tinyurl.com/ykycpgu

Could do with a lick of paint.

--
Tim

"That the freedom of speech and debates or proceedings in Parliament
ought not to be impeached or questioned in any court or place out of
Parliament"

Bill of Rights 1689


== 7 of 16 ==
Date: Mon, Feb 8 2010 3:18 pm
From: Martin Gregorie


On Tue, 09 Feb 2010 07:32:01 +1300, Ian Collins wrote:

>
> In some contexts maybe, but golf and cricket clubs had their
> "professional" long before anyone thought of developing software. It
> isn't the term "professional" that has been bastardised, it's
> "Engineer".
>
That's easy: anybody who isn't a member of a recognised engineering
society should not be called an engineer and should be laughed out of
town if they call themselves one.


--
martin@ | Martin Gregorie
gregorie. | Essex, UK
org |


== 8 of 16 ==
Date: Mon, Feb 8 2010 3:25 pm
From: James Kanze


On Feb 8, 12:25 am, "Alf P. Steinbach" <al...@start.no> wrote:
> * James Kanze:

[...]
> But strangely, one thing that motivates me is apparent peer
> disapproval. For in many social environments (last week or so
> there was a damning report about this kind of environment at
> the University of Oslo, happily I'm not there) the art of
> put-down'ing and dissing is key to personal success. When
> someone else does something really good then put-down'ing
> becomes necessary and the default response. Thus, when I get
> critique that has more emotional impact than technical I
> concentrate on the technical points. Then, interpreting those
> more technical points in a kind of inverse-picture way, I know
> what's good.

Any commercial firm which created that sort of environment would
fail very quickly. And I'll admit that I've never quite seen it
to that point. (I have seen cases where one manager tried to
cause the failure of projects for which another manager was
responsible. But I've never seen anything similar among the
technical personel.)

I've always gotten a great deal of satisfaction from peer (as
opposed to boss') approval. And it's been forthcoming in
practically every firm I've worked in---my collegues have
thought my programs good, and told me so. Even in really poorly
run shops. (Perhaps more so in poorly run shops---in the better
run shops, it was taken for granted that everyone would write
good code, and you needed to do something exceptional to get
special approval.)

> Of course, that's part of the personal satisfaction
> motivation, but I think it's interesting that personal
> satisfaction, knowing that you've created something good, in
> some/many environments can be directly incompatible with peer
> approval.

Don't work in such environments. They're dangerous for your
(mental) health. And as long as you stick to the technical
side, they are very, very rare.

> And for me personal satisfaction weights more.

> Peer approval would in most cases just say that I'm
> conforming, which is not something that I'd be proud of;

No. But it does mean that what you've done that is original can
be understood by others. Which IMHO is good.

> it's something I strive to avoid. But in some cases approval
> is really nice. E.g., a few times you've stated that I'm
> pretty good, or words to that effect, which coming from
> someone that one respects is uplifting in a way; likewise,
> once, many years ago, I had a dispute with one very well-known
> C++ expert over in clc++m and wrote some things that I really
> shouldn't have, the mod apologized for accepting the article
> by saying that he didn't read closely because it was two "C++
> experts" discussing things, and that helped much, otherwise I
> might have stopped posting... :-)

Note that approval can come in many different forms:-). At
times, I've argued strongly with you because IMO, you opinion
counts. You're not just anyone---your knowledge of C++ (and
software engineering in general) is exceptional. So when your
point of view disagrees with mine, it worries me. Which makes
me argumentive.

--
James Kanze


== 9 of 16 ==
Date: Mon, Feb 8 2010 3:26 pm
From: Seebs


On 2010-02-08, Martin Gregorie <martin@address-in-sig.invalid> wrote:
> That's easy: anybody who isn't a member of a recognised engineering
> society should not be called an engineer and should be laughed out of
> town if they call themselves one.

This strikes me as the polar opposite of an engineering mindset, which
would be that a thing is what it is, and isn't what it isn't, regardless
of any labels.

-s
--
Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam@seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!


== 10 of 16 ==
Date: Mon, Feb 8 2010 3:33 pm
From: James Kanze


On Feb 8, 4:06 pm, Lew <no...@lewscanon.com> wrote:
> MarkusSchaber wrote:
> >> I won't dispute that money is a motivator, but it is not
> >> the most efficient motivator. The more money you pay, the
> >> more you will attract those developers which are purely
> >> after the money, and not the really good ones. For the
> >> latter ones, a certain level on the paycheck is enough to
> >> give attention to fun, excitement, atmosphere and such
> >> factors.

> Dirk Bruere at NeoPax wrote:

> > I once joked with an employer that if he paid me twice as
> > much I would only have to work half as long :-)

> Given that nearly nobody gives a perfect working environment,
> or even close, money is the primary distinguisher. As a
> contract worker, I've seen a few dozen IT workplaces. The
> grass is never greener. Offer me twice as much compensation
> as the other potential employer and my talents are yours to
> exploit.

That's completely wrong. The effect of money depends on a lot
of things: someone who's just coming out of an expensive
divorce, heavily endebted, will doubtlessly put more importance
on it that a young, single person who has no debts and is making
enough to comfortably sustain the lifestyle he likes. But
environments do vary, enormously, and unless I'm under duress,
I'll always go for the position which seems to offer the better
environment. (But of course, at my level, even those positions
offer a comfortable level of life. It's generally a question of
being well off, rather than very well off.)

> It's not that money is the motivator. The question is leading
> and extremely ill cast. I don't depend on anyone else for my
> motivation. Money is the decider; it decides whether and
> where I work. It doesn't determine how.

I'll refuse jobs that aren't sufficiently paid. But I recently
changed jobs more because I was bored than because I make more
in my new job. (Formally, my income is considerably higher.
But so are my expenses---my living standard is basically
unchanged, or even a little lower than it used to be.)

--
James Kanze


== 11 of 16 ==
Date: Mon, Feb 8 2010 3:36 pm
From: James Kanze


On Feb 8, 6:46 pm, Seebs <usenet-nos...@seebs.net> wrote:
> On 2010-02-08, Dirk Bruere at NeoPax <dirk.bru...@gmail.com> wrote:

[...]
> The primary motivation there wasn't the money, it was the
> visible demonstration that the management felt it was their
> problem more than ours that the schedule had been wrong.
> (Note the emphasis; it was not that we were behind the
> schedule, it was that the schedule was, empirically, wrong.)

Yes! I think that most people fundamentally like to help
others, in one way or another. And someone saying that they
screwed up, and asking for help, is a strong motivator for most
people. On the other hand, threats almost never work. People
don't work well when they feel threatened.

--
James Kanze


== 12 of 16 ==
Date: Mon, Feb 8 2010 3:39 pm
From: Arved Sandstrom


Seebs wrote:
> On 2010-02-08, Martin Gregorie <martin@address-in-sig.invalid> wrote:
>> That's easy: anybody who isn't a member of a recognised engineering
>> society should not be called an engineer and should be laughed out of
>> town if they call themselves one.
>
> This strikes me as the polar opposite of an engineering mindset, which
> would be that a thing is what it is, and isn't what it isn't, regardless
> of any labels.
>
> -s

Insofar as competent and professional engineering societies set real
standards for qualifications and conduct to be able to use the title
"Engineer", and insofar as the vast majority of software developers have
nothing like this at all, I see no problem here.

AHS


== 13 of 16 ==
Date: Mon, Feb 8 2010 3:42 pm
From: James Kanze


On Feb 8, 4:14 pm, Malcolm McLean <malcolm.mcle...@btinternet.com>
wrote:
> On Feb 8, 1:43 am, James Kanze <james.ka...@gmail.com> wrote:
> > On Feb 5, 3:14 pm, Patricia Shanahan <p...@acm.org> wrote:

> > [...]

> > > That said, by definition professionals are, to some
> > > extent, in it for the money. If they were not, they would
> > > be amateurs as I am now. How that is balanced against
> > > interesting work, physical working conditions, status,
> > > etc. varies.

> > I'm not sure if the word "professional" has the same
> > conotations in English as it does in French, but from the
> > French meaning, I don't think you can be truely a
> > "professional" if you're only in it for the money.
> > "Professional" implies being paid for what you do, but it
> > also implies a certain degree of personal standards with
> > regards to quality and such---a "professional" will take
> > pride in his work.

> Strictly a "professional" is someone who is a member of a
> professional body which regulates itself and has the right to
> control entry to the profession. For instnace I can't simply
> buy scalpels and antiseptic and set myself up as a brain
> surgeon - I have to go throguh the British Medical Association
> before they'll let me chop people up. the same is true for
> lawyers, accountants, and some other more obscure niches.

Words have many meanings, and some professions are "reglementé".
Still, in France, I was a "profession libérale", and not a
"commerçant" or "artisan"---in Germany, the categorie was
"freiberuflich", rather than "Gewerber". These are very
distinct legal categories, with (especially in Germany)
implications with regards to how I was taxed, etc. (And it did
lead to some interesting situations in France, since typically,
as a "profession libérale", I was asked for my registration with
the professional association. Which didn't exist for my
profession.)

--
James Kanze


== 14 of 16 ==
Date: Mon, Feb 8 2010 3:44 pm
From: Phil Carmody


Ivan Marsh <ivanmarsh@yahoo.com> writes:
> Lew wrote:
>> Ivan Marsh wrote:
>>> The 1950's [sic] were totally awesome.
>>
>> Oh, yeah - the twin evils of McCarthyism and Communism. Racism. Sexism.
>> The
>> Cold War. Superpowers playing chess with smaller countries. Wars
>> everywhere.
>> Dictators. Massive stockpiling of nuclear and chemical weapons. Rapine
>> of
>> the planet. The birth of AIDS. Hideous fashions.
>>
>> Totally awesome.
>
> The complete lack of sarcasm...

No, I think you'll find that Tom Lehrer was quite active in
those days.

Phil
--
Any true emperor never needs to wear clothes. -- Devany on r.a.s.f1


== 15 of 16 ==
Date: Mon, Feb 8 2010 3:50 pm
From: Seebs


On 2010-02-08, Arved Sandstrom <dcest61@hotmail.com> wrote:
> Seebs wrote:
>> On 2010-02-08, Martin Gregorie <martin@address-in-sig.invalid> wrote:
>>> That's easy: anybody who isn't a member of a recognised engineering
>>> society should not be called an engineer and should be laughed out of
>>> town if they call themselves one.

>> This strikes me as the polar opposite of an engineering mindset, which
>> would be that a thing is what it is, and isn't what it isn't, regardless
>> of any labels.

> Insofar as competent and professional engineering societies set real
> standards for qualifications and conduct to be able to use the title
> "Engineer", and insofar as the vast majority of software developers have
> nothing like this at all, I see no problem here.

Membership in an organization is not the same thing as meeting the formal
standards that would be required by such an organization if it existed.

In short, if there exists a set of qualifications and conduct which would
be necessary to be a member of an organization, and membership confers the
title "engineer", then having that set of qualifications and conduct ought
to confer the title *with or without* membership in the organization.
Meanwhile, at least some members of any given organization will usually
not actually meet the nominal or formalized standard in one way or another.

Measurement by proxy is not very good measurement.

-s
--
Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam@seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!


== 16 of 16 ==
Date: Mon, Feb 8 2010 4:01 pm
From: Arved Sandstrom


Seebs wrote:
> On 2010-02-08, Arved Sandstrom <dcest61@hotmail.com> wrote:
>> Seebs wrote:
>>> On 2010-02-08, Martin Gregorie <martin@address-in-sig.invalid> wrote:
>>>> That's easy: anybody who isn't a member of a recognised engineering
>>>> society should not be called an engineer and should be laughed out of
>>>> town if they call themselves one.
>
>>> This strikes me as the polar opposite of an engineering mindset, which
>>> would be that a thing is what it is, and isn't what it isn't, regardless
>>> of any labels.
>
>> Insofar as competent and professional engineering societies set real
>> standards for qualifications and conduct to be able to use the title
>> "Engineer", and insofar as the vast majority of software developers have
>> nothing like this at all, I see no problem here.
>
> Membership in an organization is not the same thing as meeting the formal
> standards that would be required by such an organization if it existed.
>
> In short, if there exists a set of qualifications and conduct which would
> be necessary to be a member of an organization, and membership confers the
> title "engineer", then having that set of qualifications and conduct ought
> to confer the title *with or without* membership in the organization.
> Meanwhile, at least some members of any given organization will usually
> not actually meet the nominal or formalized standard in one way or another.

At the moment those standards do not exist for the majority of software
developers. So it's pretty much a moot point.

If the standards did exist, how would you know that a person who claimed
a title actually deserved it, without having them go through a
certification process?

[ SNIP ]

AHS

==============================================================================
TOPIC: C++ and shared objects
http://groups.google.com/group/comp.lang.c++/t/c0dc99feb20c6b5f?hl=en
==============================================================================

== 1 of 1 ==
Date: Mon, Feb 8 2010 2:39 pm
From: James Kanze


On Feb 8, 6:46 am, Robert Fendt <rob...@fendt.net> wrote:
> And thus spake Phoenix87 <phoenix1...@gmail.com>
> Sun, 7 Feb 2010 16:14:50 -0800 (PST):

> > I want to build some shared libraries from C++ code defining
> > classes because I want to load them dynamically in programs
> > that need that classes. I've read about dlopen and co.,
> > which require the implementation of factory procedures in
> > order to dynamically allocate class instances from the
> > loaded shared object. Is there an alternative way to
> > dynamically load classes in C++ programs? I mean something
> > which allows to instantiate new class instances with new
> > keyword etc...Basically my question is quite the same thing
> > as asking how the STL, or the CERN ROOT libraries work.

> STL is a template framework. It therefore does not consist of
> any runtime libraries apart from the C standard stuff
> underneath.

It depends on what you mean by "STL". Traditionally, it did
refer to a library created by Stepanov, which in fact was almost
exclusively templates. Most people today, however, use the term
STL to refer to the standard library. In which case, it's
provided somehow by your compiler, and you don't really have to
know the details. (And it's not all templates.)

Of course, the real problem is that he doesn't really say what
he's trying to do, so it's difficult to find a solution. In
general, if you're providing a library for other programs,
you'll provide a set of headers, a dynamic object *and* a static
library, since except in exceptional cases, the client will
probably prefer linking statically. (If nothing else, unless
you're freeware, the licensing issues for DLL's will be a
nightmare.)

> In order for a direct 'new' to work, the class definition has
> to be available (header file) as well as the object files
> containing all non-inline functions.

And in order for a factory method to work, and external
declaration of the factory method must be present. And to use
whatever the factory method returns, you also need headers which
declare the interface. In the end, it's purely a question of
what and how you want to provide something.

> So you just can build a shared library of your stuff and use
> it for regular compiling and linking against. In this case,
> the system's runtime facilities will do the loading of the
> dynamic library for you at program startup.

With some notable exceptions, if that's the case, you should
probably be linking statically.

> This is straight-forward, and I do not interpret your question
> in that direction. You seem to think about dynamic loading
> rather than dynamic linking.

> Dynamic loading means that you load something your compiler
> did not know about. If you look at the specifications of
> dlopen() and such (the Windows equivalents have similar
> restrictions), you will find that the framework just allows
> for retrieval of unmangled (i.e. plain C) symbols. This works
> for constants and for function pointers (although the ability
> to retrieve a function pointer directly through dlsym() is
> technically a non-standard compiler extension, albeit a
> popular one).

The interface (both under Unix and under Windows) allows for
loading just about anything. (Windows is somewhat more
restrictive here, I think.) All you have to do is give the name
according to the local conventions, which means mangled in the
case of Windows or Unix. On the other hand, you also have the
problem that the function returns a void* (Unix) or a void (*)()
(Windows), which means you'll also need some casting. And no
doubt, headers, to define what you'll be casting to. In
practice, because of the mangling, the easiest solution is to
provide an ``extern "C"'' factory function. (Typically, the
mangling used by C is far simpler than that used by C++.) But
the client code still needs the header files to know the target
type of the cast, and the type actually returned.

> Long story short: you really can only get a pointer to a
> factory function by using dlsym() (POSIX) or GetProcAddress()
> (Windows). There is no way around it, just live with it.

That's false. With both, you can get a pointer to anything.
And if the library contains classes which have been exported
(and under Unix, by default, everything has been exported), you
can new them. But you need a header file with the concrete type
to do so.

> Loading C++ classes directly would involve all sorts of pains
> and hassles, not to mention a change to the C++
> specifications, and since at least POSIX does not deal with
> C++ anyway, dlsym() will not be changed in the near future. I
> do not know about Microsofts's plans for VC and
> GetProcAddress, but I would be surprised.

GetProcAddress is almost exactly like dlsym, except that it
returns the address of a function, rather than the address of
data, But since both Windows and Unix require the two to have
the same representation, all it takes is some very ugly funny
casting to get from one to the other. (As luck would have it,
every time I've used dlsym, I've needed the address of a
function, but the first time I used GetProcAddress, it was to
obtain the address of data.)

In general, I think what you're trying to say is correct, but
the issues are far more complicated than one would guess from
your posting.

--
James Kanze

==============================================================================
TOPIC: B const * array[ ] in gobal
http://groups.google.com/group/comp.lang.c++/t/539f80e07ceb283b?hl=en
==============================================================================

== 1 of 2 ==
Date: Mon, Feb 8 2010 2:55 pm
From: James Kanze


On Feb 8, 1:55 pm, soft wind <soft_w...@nifty.com> wrote:
> I have a problem about an object ( B const * array[ ] ) in
> global. Please see source program below.

> I provide B * const array [ ] in global scope in my first try,
> but their lifetime seems to be already end when the program
> goes to the enrty of main function.

> why is it so ?
> I usually provide char const * array[ ] in global and goes
> well. In which page does the standard describe about
> lifetime in this case ?
> Maybe '3.8 Object lifetime", but which phrases are applied in this
> case?

> In my second try, it goes well but another structure (class)
> is required. Is there any better way to provide B * pointer
> to handle late binding ?

> ------------------------------------------------------------------
> #include <string>
> #include <iostream>

> using std::string;
> using std::cout;

> class B {
> public:
> B( string str ) : str_m( str ) { }
> string get_str( void ) const { return str_m; }

> virtual int fnc( void ) const = 0;
> virtual ~B( ) { }

> private:
> std::string str_m;
> };

> class D : public B {
> public:
> D( string str ) : B( str ) { }

> virtual int fnc( void ) const { return 1; }
> };

> struct Create_B {
> string str_m;
> B * (*fnc)( string str );
> };

> B * create_D( string str )
> {
> return new D( str );
> }

> B const * list_0[ ] = {
> & D( "D0" ),

This shouldn't compile. I don't see any user defined overload
of D::operator&, so & is the built in operator, which requires
an lvalue.

If it does compile, you're using an implementation specific
extention, not C++, and you'll have to verify in the
implementation documentation what it means with regards to
lifetime of objects.

(Personally, I'd be very suspicious of a compiler with such
extensions, as it suggests that the people who wrote the
compiler don't understand C++.)

> };

> D const list_1[ ] = {
> D( "D1" ),
> };

> Create_B list_2[ ] = {
> { "D2", &create_D },
> };

> int main( void )

Just a nit, but the void marks you as a C programmer, and gives
the impression that you don't know C++.

> {
> // My first try, but fails
> s = list_0[ 0 ]->get_str( );

What is "s"? I don't see it declared anywhere.

As for the rest, see your compiler documentation; the
initialization of list_0 isn't C++, but some compiler specific
extention, so only the compiler documentation can tell you what
to expect.

> cout << s << "\n";

> // just for checking what is wrong with the first try
> string s;
> s = list_1[ 0 ].get_str( );
> cout << s << "\n";

This is well defined behavior: it should call the get_str
function on a copy of the D object used to initialize list_1.

> // My second try runs without error,
> // but another class 'Create_B' is required
> B * p = list_2[ 0 ].fnc( list_2[ 0 ].str_m );
> s = p->get_str( );
> cout << s << "\n";

This is also legal, but has distinctly different semantics than
the first two, since it creates a new object on the heap.

> return 0;
> }

--
James Kanze


== 2 of 2 ==
Date: Mon, Feb 8 2010 2:57 pm
From: James Kanze


On Feb 8, 2:46 pm, Victor Bazarov <v.Abaza...@comAcast.net> wrote:
> soft wind wrote:
> > [..]
> > B const * list_0[ ] = {
> > & D( "D0" ),
> > };

> Here you initilialise the pointer (the first element of your
> array) with the address of a *temporary*.

Maybe. The code is not legal C++, and requires diagnostic. If
he doesn't get an error message, he's not using a C++ compiler,
but something else. And what the statement does depends on what
that something else defines it to do.

--
James Kanze

==============================================================================
TOPIC: int (*&)()
http://groups.google.com/group/comp.lang.c++/t/889d2547688e2155?hl=en
==============================================================================

== 1 of 4 ==
Date: Mon, Feb 8 2010 2:59 pm
From: James Kanze


On Feb 8, 3:45 am, Asif Zaidi <asifnza...@gmail.com> wrote:
> What does the syntax in subject line mean - how should I read
> it.

According to the rules of type expressions. A reference to a
pointer to a function taking no arguments and returning int.

--
James Kanze


== 2 of 4 ==
Date: Mon, Feb 8 2010 3:05 pm
From: James Kanze


On Feb 8, 12:58 pm, Asif Zaidi <asifnza...@gmail.com> wrote:
> On Feb 8, 12:28 am, Syron <mr.sy...@googlemail.com> wrote:

> > Am 08.02.2010 04:45, schrieb Asif Zaidi:

> > > What does the syntax in subject line mean - how should I
> > > read it.

> > if this is a typedef (like 'int(*&func)()') it is a
> > reference to a pointer to a function that returns an int.

> I am trying to implement the following and getting compile
> failure. Any suggestions ?

> typedef int (*& func_ptr1)();

> int goo()
> {
> cout << "un goo" << endl;
> return 0;
> }

> int main()
> {
>
> func_ptr1 p1 = goo;
> }

Why? The formal reason why it doesn't work is that you're
trying to initialize a reference to a non-const with an rvalue.
But the real question is "what do you think you're trying to
do?" To make the above work, it's sufficient to change the
typedef to:

typedef int (*const & func_ptr1)();

But while the results may be legal C++, they still don't make
any logical sense.

> The error is below

> 1>d:\profiles\waz003\my documents\visual studio 2008\projects
> \hw5_3\hw5_3\hw5_3.cpp(174) : error C2440: 'initializing' : cannot
> convert from 'int (__cdecl *)(void)' to 'func_ptr1'

The error message could be better, the fact remains: you can't
initialize a reference to a non-const with an rvalue. Given,
however, that at least in the above case, it doesn't make any
sense to even want to, the question remains: what are you really
trying to do?

--
James Kanze


== 3 of 4 ==
Date: Mon, Feb 8 2010 3:09 pm
From: James Kanze


On Feb 8, 1:40 pm, Asif Zaidi <asifnza...@gmail.com> wrote:
> On Feb 8, 7:12 am, Victor Bazarov <v.Abaza...@comAcast.net> wrote:

[...]
> The first option you state: why does it work. I had the same
> thing you had except I did NOT have the const in the typedef
> definition. Why would the const help ?

Because the standard says so. Basically, when initializing a
reference, you need an lvalue, unless it is a reference to
const. (Strictly speaking, Victor was wrong when he said you
needed a modifiable lvalue: you need an lvalue whose type is not
const, which isn't quite the same thing. Morally, however, if
it's not the same thing, then you're cheating somewhere, and
you're going to have troubles down the road.)

--
James Kanze


== 4 of 4 ==
Date: Mon, Feb 8 2010 3:13 pm
From: James Kanze


On Feb 8, 2:34 pm, Syron <mr.sy...@googlemail.com> wrote:
> Am 08.02.2010 14:40, schrieb Asif Zaidi:
> > On Feb 8, 7:12 am, Victor Bazarov<v.Abaza...@comAcast.net> wrote:
> > [...]

> > Thanks Victor - a few questions though

> > The first option you state: why does it work. I had the same
> > thing you had except I did NOT have the const in the typedef
> > definition. Why would the const help ?

> > The second option you state: that is just a function ptr is
> > it not. It is not a reference to a ptr to a function which
> > is what I want ?

> if a function pointer would not be const, you could do some
> REALLY stupid things like "funcPtr++".

The ++ operator isn't supported on function pointers. But
non-const function pointers do make sense---in fact, why use a
pointer to a function, instead of calling the function directly,
if the pointer is const?

> and as I now think about that, a reference to a const pointer
> does not really make sense, does it?

Yes and no. It's generally simpler to use the pointer directly,
but such references are likely to occur in templates and such.
If you instantiate:
std::vector< int (*)() >
, some of it's functions, like push_back, will take references
to const pointers.

--
James Kanze

==============================================================================
TOPIC: Never seen this usage before
http://groups.google.com/group/comp.lang.c++/t/9a99c229e104389e?hl=en
==============================================================================

== 1 of 1 ==
Date: Mon, Feb 8 2010 3:44 pm
From: l h


I'm looking over some C++ code and I came across a class definition
that I don't understand the purpose of. If someone could tell me what
kind of construct this is and its purpose, I'd appreciate it.

class A
{
public:
typedef A Adesc;
typedef B::C<Adesc> B1;
typedef B::D<Adesc> B2;
};

What is the intent of this class of typedefs and what is it used for?

Thanks.

Les

==============================================================================
TOPIC: Classes named CFoo (was Re: Odd Exception Behavior)
http://groups.google.com/group/comp.lang.c++/t/ce3a580936f3cddd?hl=en
==============================================================================

== 1 of 1 ==
Date: Mon, Feb 8 2010 5:10 pm
From: Branimir Maksimovic


Jorgen Grahn wrote:
> On Thu, 2010-02-04, none wrote:
>> Alf P. Steinbach wrote:
> ...
>>> * "C"-prefix for a class is a Microsoft-ism, therefore (almost
>>> automatically)
>>> ungood.
>> Guilty as charged. I've been using the "C" prefix since the early days
>> of Visual Studio.
>
> More generally: I see this class CFoo scheme in a lot of postings
> here. Why do people use it, *really*?

I beleive that C is hungarian notation. C stands for "class".

S is for struct, I guess?

Greets

==============================================================================

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: