Name Mangling in DDK

S

sunny

Hi,
I was trying to call a function in an an asm file from a C
file(driver).

In c file the funcrtion is defined as:
extern int foo(int,int);
In the asm file the function is defined as _foo.

when I link the 2 binaries in VC++ it works fine but with DDK this
gives as error saying _foo@8 not found.

Is there a way to do away with this name mangling.
Since this driver is to be used on both 32 and 64 bit platforms I dont
want the number changing from one version to another.

Thankx a zillion.
Sunil.
 
J

JKop

sunny posted:
Hi,
I was trying to call a function in an an asm file from a C
file(driver).

In c file the funcrtion is defined as:
extern int foo(int,int);
In the asm file the function is defined as _foo.

when I link the 2 binaries in VC++ it works fine but with DDK this
gives as error saying _foo@8 not found.

Is there a way to do away with this name mangling.
Since this driver is to be used on both 32 and 64 bit platforms I dont
want the number changing from one version to another.

Thankx a zillion.
Sunil.

comp.lang.c


As for C++,

extern "C" int foo(int,int);


-JKop
 
J

John Harrison

Hi,
I was trying to call a function in an an asm file from a C
file(driver).

In c file the funcrtion is defined as:
extern int foo(int,int);
In the asm file the function is defined as _foo.

when I link the 2 binaries in VC++ it works fine but with DDK this
gives as error saying _foo@8 not found.

Is there a way to do away with this name mangling.
Since this driver is to be used on both 32 and 64 bit platforms I dont
want the number changing from one version to another.

Thankx a zillion.
Sunil.

Try

extern "C" foo(int, int);

There are no guarantees that this will work, because linking issues and
name mangling are not part of the C++ language. But in many
C++ implementations this has the effect of turning off name mangling.
 
P

Phlip

sunny said:
I was trying to call a function in an an asm file from a C
file(driver).

In c file the funcrtion is defined as:
extern int foo(int,int);

Are you sure it's C? It could be C++.
In the asm file the function is defined as _foo.

when I link the 2 binaries in VC++ it works fine but with DDK this
gives as error saying _foo@8 not found.

If it's really C++, add extern "C" to the function declaration (not
"definition").
 
R

Robert Wessel

Hi,
I was trying to call a function in an an asm file from a C
file(driver).

In c file the funcrtion is defined as:
extern int foo(int,int);
In the asm file the function is defined as _foo.

when I link the 2 binaries in VC++ it works fine but with DDK this
gives as error saying _foo@8 not found.


Making the definition:

extern "C" {int foo(...);}

should consistently get you an external name with only a leading
underscore and no trailing decoration. Be aware of the distinction
between __cdecl and __stdcall conventions. If you're calling external
code you may want to specify one or the other explicitly, rather than
depending on the compiler command line or default.

Is there a way to do away with this name mangling.
Since this driver is to be used on both 32 and 64 bit platforms I dont
want the number changing from one version to another.


Since you'll need to write a completely different assembler module for
the 64 bit platform(s) you intend to support, there's real no
advantage to having the name consistent between platforms, just so
long as it holds still on any given one.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top