Name Mangling in DDK

  • Thread starter Thread starter sunny
  • Start date Start date
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.
 
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
 
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.
 
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").
 
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.
 
Back
Top