Re: default argument and shared library
On Aug 3, 10:44 am, Sarvesh Singh <sarvesh.si...@gmail.com> wrote:
On Aug 3, 1:25 pm, James Kanze <james.ka...@gmail.com> wrote:
On Aug 3, 9:12 am, "Fred Zwarts" <F.Zwa...@KVI.nl> wrote:
"S S" <sarvesh.si...@gmail.com> wrote in
messagenews:ee03b4d3-f3f1-4bdf-99a2-2dd79bce8f08@r2g2000yqm.googlegro=
ups.com...
[...]
The use of shared libraries is not defined in the C++ standard.
So?
This is a operating system dependent question, which is
not in the scope of this newsgroup.
Not really. The answer to his question will be pretty much
the same, regardless of the OS.
Formally speaking, limiting oneself to the standard, his
code has undefined behavior, because it contains a violation
of the one definition rule. This has nothing to do with
dynamic linking; he has compiled part of the program with
one declaration of the function, and part with a different
declaration.
In other newsgroups you might get better answers. I don't
see a reason why the compiler could not put the default
value in the main executable. After all, the a.h file is
included in main.cc. But the question why it is
implemented like this, I cannot answer, except that I
guess that it is easier to implement.
Actually, if you read the standard closely, you'll realize
that about the only plausible implementation evaluates the
default argument at the call site.
This is real nightmare for industry where we need to write
different version of function everytime we add new argument. I
can not remove extern C because then user may not find the
function name if he is using C compiler. So extern C helps for
both compilers compatibility.
The "nightmare" would be to allow an existing function to change
its signature. In C++, there's no real problem---you use
namespaces for versioning, and you can usually add non-member
functions to the interface without the need to create a new
version. (Although this may also lead to confusion if
overloading is involved.) If you use ``extern "C"'', on the
other hand, you're locked into the rules which hold for C, which
means no function overloading, and no versionning.
Preserving old functions solves the purpose to support
backward compatiblity. Some executables might want to use new
shared library with old executable version. Hence single
library for all executable version support is the problem.
Don't know how to imitate this default argument thing,
currently I am adding new functions to this. Any suggestions?
Forget about ``extern "C"''. Use namespaces for versionning.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34