This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: what is the difference of binding under gcc and M$ VC 6?
- From: llewelly at xmission dot com
- To: "Kun Wei" <weikun at caltech dot edu>
- Cc: <gcc-help at gcc dot gnu dot org>
- Date: 31 Mar 2004 19:46:51 -0700
- Subject: Re: what is the difference of binding under gcc and M$ VC 6?
- References: <004001c41756$4bb47340$c070d783@KunDesktop8200>
"Kun Wei" <weikun@caltech.edu> writes:
> Hi, I have a project developed on openh323, because it is a more
> general C++ questions, I would like some C++ experts give me some
> hints.
If your question is really just about c++, you will get better results
from comp.lang.c++.moderated, or comp.std.c++ .
However it appears you are trying to make a MSVC++ emulate a gcc on
linux behavior - unfortunately for you I suspect there are not
many MSVC++ wizards on gcc-help. :-( Certainly I am not one.
>
> We customize some functions to comply our need, the details as follow:
>
> on open323 lib, we have a h323rtp.h header file declare
>
> virtual BOOL OnReceivedPDU( H323_RTPChannel & channel, /// Channel
> using this session.
>
> const H245_H2250LogicalChannelParameters & param, /// Acknowledgement
> PDU
>
> unsigned & errorCode /// Error on failure
>
> );
>
> and in source h323rtp.c defines
>
> BOOL H323_RTP_UDP::OnReceivedPDU(H323_RTPChannel & channel,
>
> const H245_H2250LogicalChannelParameters & param,
>
> unsigned & errorCode)
>
> {
>
> //some code here
>
> }
>
>
> To comply our need, we override the function in our own application
> code with exactly same signature
>
> BOOL H323_RTP_UDP::OnReceivedPDU(H323_RTPChannel & channel,
>
> const H245_H2250LogicalChannelParameters & param,
>
> unsigned & errorCode)
>
> {
>
> //some customized code here
>
> }
>
>
> When I build it with gcc under Linux, the funtion in our applicatoin
> gets called, which is what we want. But when I compile/build it with
> M$ Visual Studio C++ 6.0, it seems only the original function in
> h323rtp.c is called, out customized function is never called.
The C++ standard says your code is ill-formed and no diagnostic is
required, because your code violates the One Definition Rule -
that is, you have two definitions of
H323_RTP_UDP::OnReceivedPDU(H323_RTPChannel & channel, const
H245_H2250LogicalChannelParameters & param,unsigned & errorCode )
in seperate translation units. Since no diagnostic is required
(and ISO C++ never requires code be rejected), your C++ compilers
are free to generate no warnings, no errors, and do whatever they
like.
The linux behavior is due to the old unix linker tradition - when a
new object file is linked in, symbols defined in the new object
file are used only to resolve symbols not already resolved. So
when your application provides a definition, the uses of that
symbol get resolved (to use your definition) before the library is
linked in, and the library's definition is never used.
I don't use MSVC++, so I can't explain its behavior, except to say
that windows generally has no respect for unix traditions. :-)
> So what is the difference between these 2 environments? How can my
> customzied function also get called in Windows?
[snip]
Perhaps you could experiment with the cygwin or mingw ports of gcc -
see cygwin.com and mingw.org respectively.
Also, try asking in a forum specific to Visual C++, codewarrior, etc -
a Visual C++ or codewarrior wizard might be present and know how
to trick said compiler into giving you what you want.