1

I am wondering if you can use a c++ header file to interface your assembly functions.

For example: I have hello.asm with a hello_world function, wich uses the calling conventiens that your c++ compiler uses, a hello.h header file wich has a symbol: void hello_world(int file_descriptor), and a third main.cpp file wich defines hello.h, the header and uses the function hello_world described in the header.

Now when you link the main.o file and the hello.o (origins from the hello.asm) file, will you be able to call the assembly functions: hello_world(int file_descriptor) from the main file?

And if you can, is this a good conventien to follow when I am using alot of extern functions, replacing the extern keyword?

Vexea
  • 167
  • 1
  • 1
  • 8
  • 1
    Yes, you should. Did you try it? – Robert Andrzejuk Jan 29 '22 at 18:00
  • Not yet, I don't have my computer on me and this question popped into my head. – Vexea Jan 29 '22 at 18:01
  • 1
    Multiple file compilation and mixed languages are a commonly supported scenarios. Just have to be careful about calling conventions and name mangling. See [Foreign Function Interface](https://en.wikipedia.org/wiki/Foreign_function_interface) for more information. – Erik Eidt Jan 29 '22 at 18:20
  • 4
    It can be a good idea to add `extern "C"` in the header, to use the C calling convention. Otherwise the asm file will have to use a name like `?hello_world@@YAXH@Z` when the compiler encodes the parameter type for a possibly overloaded C++ function. – BoP Jan 29 '22 at 20:51

0 Answers0