delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/07/30/16:13:05

Date: Fri, 30 Jul 1999 14:11:44 +0200
From: Hans-Bernhard Broeker <broeker AT physik DOT rwth-aachen DOT de>
Message-Id: <199907301211.OAA06806@acp3bf.physik.rwth-aachen.de>
To: djgpp AT delorie DOT com
Subject: Re: Yet another question about C++
Newsgroups: comp.os.msdos.djgpp
Organization: RWTH Aachen, III. physikalisches Institut B
X-Newsreader: TIN [version 1.2 PL2]
Reply-To: djgpp AT delorie DOT com

In article <19990729051304 DOT 21198 DOT rocketmail AT web130 DOT yahoomail DOT com> you wrote:
> class point
> {
>    int x;
>    void some_func();
>   public:
>    void draw_it();
> }

> Now... some_func() was NOT in the .cpp file!! it is in
> an asm file and compiled using NASM, not djgpp!

You're making life miserable for yourself, I'd say. Writing C++
methods in assembly is hard enough on its own. Using a different
assembler than the compiler itself does makes it even more
complicated.

Here's the recipe, in a rough outline:

Write a C++ dummy implementation of point::some_func(). Be sure to 
check that it does use 'x'. Now, compile that C++ function to (gas)
assembly:

	gcc -S somefunc.cc

You'll get a file 'somefunc.s' containing the assembly code gcc
itself would have used, for this.

Next, you'll have to translate that assembly from AT&T to Intel-style
assembly, and you have the prototype how to write your NASM module.

OTOH, it might be way easier to *not* write the method itself in assembly.
Just write a normal assembly function under whatever name you like, and
implement point::some_func as an inline function:

extern "C" { 
  void the_real_point_some_func(int *x);
}

class point {
 int x;
 void some_func() {the_real_some_func( &x); };
 //... 
}

--
Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de)
Even if all the snow were burnt, ashes would remain.

- Raw text -


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