Mail Archives: djgpp/1997/05/04/20:37:41
[Posted and mailed]
In the referenced article, ma6djh AT bath DOT ac DOT uk (D J Hampson) writes:
> I've just realised that when you compile C++ it gives functions
> different names like _MyFunc_Fss (ss standing for short short),
> rather than just _MyFunc. This makes sense for overloading and
> stuff, but doesn't it mean that C++ is incompatible with Assembler
> built for C?
>
> If I put MyFunc(short,short) in C, and then _MyFunc in Asm, how do
> I make it compile correctly under C and C++? (How do I make C++
> look for a function called _MyFunc rather than _MyFunc_Fss?)
Sigh, once again we see the cardinal Usenet sin of questions being
broadcast to the whole world *BEFORE* being asked of the local
support services. Asking questions of the local support services
may not have the same cachet as asking the whole world. And we may
not know too much about the C++ language. But we can certainly
answer questions such as this.
To do what you want you use an extension of the linkage specification
that was introduced into C++. For example:
extern "C" {
double sqrt(double);
}
The above tells the C++ compiler that the name sqrt uses C naming
conventions and that the compiler shouldn't go through the usual
name mangling contortions to cater for overloaded function names.
You can find all of this discussed in the section on Overloading and
Linkage, pp232-234, of the book:
The Design and Evolution of C++, Bjarne Stroustrup, Addison-Wesley, 1994,
ISBN 0-201-54330-3
You may find further details in:
TITLE: The annotated C++ reference manual / Margaret A. Ellis, Bjarne
Stroustrup
PUBLISHER: Reading : Addison-Wesley, c1990
NOTES: "Copyright by AT&T Bell Telephone Laboratories"
ISBN: 0201514591
The University Library has a copy of the above book (the above
details are taken from its catalogue) but the book is currently out
on loan.
--
Dennis Davis, BUCS, University of Bath, Bath, BA2 7AY, UK
D DOT H DOT Davis AT bath DOT ac DOT uk
- Raw text -