Dead Hackers Society
Other BBSes »
 
 
Demoscene  Coding  CT60  Buy/sell

Atari coding BBS
 
Re: GCC + assembler problem
Posted by: Kalms Feb,20.2006-02:24 

Your problem is probably due to the C++ name mangling rules.

In C++, the name of a function such as:

int myfunction(int x, int y);

will, during compile time, be translated into a "decorated" name such as: __myfunction$$II

... where the decorated name contains all the information necessary to distinguish that version of 'myfunction' from any other ones (overloaded versions, class methods which also happen to be named 'myfunction', any 'myfunction' functions in other namespaces etc).

The name mangling allows an ordinary linker to be used for C++ code, without giving it any extra knowledge about C++'s class/namespace rules.

Both data objects and function names get "decorated" this way.

What you want to do, is to tell the C++ compiler, that a certain set of symbols should not get the C++ name mangling, but instead be treated according to the original C name mangling rules (just put an '_' in front of the name). You do that by putting an 'extern "C" { ... };' around it. Example:

extern "C" {
extern int variableInCProgram;
int functionInCProgram(int x, int y);
};

And this is how you declare code/data inside the C++ file, while making it accessible to C/assembly modules:

extern "C" {
int variableWhichShallBeAccessibleFromCProgram;
int functionWhichShallBeAccessibleFromCProgram(int x, int y); // function body is written further down in this source file
};

Hope this helps.







[All messages in this thread]    [Start new thread]

Topic Posted by  Date 
GCC + assembler problem Peter Feb,16.2006-23:56
  Re: GCC + assembler problem tobe Feb,17.2006-00:14
    Re: GCC + assembler problem Peter Feb,17.2006-09:23
      Re: GCC + assembler problem tobe Feb,17.2006-14:00
        Re: GCC + assembler problem Peter Feb,21.2006-09:35
    Re: GCC + assembler problem ggn/KUA Feb,17.2006-15:58
      Re: GCC + assembler problem Peter Feb,21.2006-09:35
  Re: GCC + assembler problem Patrice Mandin Feb,17.2006-20:00
    Re: GCC + assembler problem Peter Feb,20.2006-09:29
  Re: GCC + assembler problem Kalms Feb,20.2006-02:24
    Re: GCC + assembler problem Peter Feb,20.2006-09:25
      Re: GCC + assembler problem Peter Feb,21.2006-09:28


Reply to this message
Name:
Topic:
Anti-troll code:

Message:

What's the anti-troll code?
That's your personal code to be able to add comments and messages on the dhs.nu site.
Don't have a code or forgot it? Fix it here.
© 1994-2024 Dead Hackers Society Contact: Anders Eriksson