www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/05/04/20:37:41

Newsgroups: comp.os.msdos.djgpp
From: ccsdhd AT bath DOT ac DOT uk (Dennis Davis)
Subject: Re: C++ and Assembler
Reply-To: The Support Mailing List <support AT bath DOT ac DOT uk>
Organization: Bath University Computing Services, UK
Message-ID: <E9E8Cq.BJE.B.mary@bath.ac.uk>
References: <E9B6tt DOT 1qy DOT C DOT amo AT bath DOT ac DOT uk>
Mime-Version: 1.0
Date: Tue, 29 Apr 1997 09:43:38 GMT
Lines: 51
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

[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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019