Re: Is nobody using c++ and/or plugs-lib? was Re: nios c++ and ethernet [may by ot?]

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
Quoted text here. Click to load it

And for those C++ "boneheads" wondering what this does:  It is equivalent to
putting an extern "C" modifier in front of all the function declarations in
the contained header file.  Why is this needed?  Because C++ uses
"name-mangling" to turn the user-friendly names you see in your code into
nearly unreadable function names that incorporate function name, type
information of the arguments, and likely some other stuff.  The reason it
does this is that you can have overloaded functions that have same name and
different argument types, but the compiler wants to generate object code
that any old linker can properly link (I think).  There are probably other
reasons (like, where else would it store the type info?) that I can't think
of.

Bottom line, by saying extern "C" you're telling the compiler that the
function will not have multiple variants and thus the compiler should use
the straight-forward name, which is just the function name with a _ in front
(assuming __cdecl calling convention) rather than the mangled name.  This is
needed because the library you are linking to (or C files) were compiled by
a C-compliant compiler that did not mangle the names.

Besides linking to C code, this can be handy when cutting down on the size
of the debug information in your executable.

And just in case you're a C/C++ coder and were confusing this with calling
conventions (as I was until recently), C & C++ have the same default calling
convention (__cdecl).  That is, there is no difference in the way they pass
function parameters and return values on the stack/registers -- they both
pass parameters on the stack with the caller responsible for stack clean-up.

Paul Leventis
Altera Corp.



Re: Is nobody using c++ and/or plugs-lib? was Re: nios c++ and ethernet [may by ot?]
Many thanx for that great insight!

Regards
g.k.



Re: Is nobody using c++ and/or plugs-lib? was Re: nios c++ and ethernet [may by ot?]
snipped-for-privacy@yahoo.com (Jesse Kempa) writes:

Quoted text here. Click to load it

This should have been done *inside* plugs.h:

#ifndef _plugs_
#define _plugs_

#ifdef __cplusplus
extern "C" {
#endif
...
#ifdef __cplusplus
}
#endif
#endif // _plugs_

This type of structure is used in excalibur.h so it should have been
done in plugs.h too (at least for consistency).

Petter
--
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
We've slightly trimmed the long signature. Click to see the full one.
Re: Is nobody using c++ and/or plugs-lib? was Re: nios c++ and ethernet [may by ot?]
Quoted text here. Click to load it

Yes, it should be.  I will file a Software Problem Report on this today.

Paul Leventis
Altera Corp.



Site Timeline