Linkage Specification. McGraw-Hill The Complete Reference Fourth Edition
Reklama
Reklama
C h a p t e r 2 3 : N a m e s p a c e s , C o n v e r s i o n F u n c t i o n s , a n d O t h e r A d v a n c e d T o p i c s
617
Here, instruction is any valid assembly language instruction. Because of the implementation- specific nature of asm, you must check the documentation that came with your compiler for details.
At the time of this writing, Microsoft's Visual C++ uses _ _asm for embedding assembly code. It is otherwise similar to asm.
Here is a simple (and fairly "safe") example that uses the asm keyword:
#include <iostream> using namespace std; int main()
{ asm int 5; // generate intertupt 5
} return 0;
When run under DOS, this program generates an INT 5 instruction, which invokes the print-screen function.
A thorough working knowledge of assembly language programming is required for using the asm statement. If you are not proficient with assembly language, it is best to avoid using asm because very nasty errors may result.
Linkage Specification
In C++ you can specify how a function is linked into your program. By default, functions are linked as C++ functions. However, by using a linkage specification, you can cause a function to be linked for a different type of language. The general form of a linkage specifier is extern "language" function-prototype where language denotes the desired language. All C++ compilers support both C and
C++ linkage. Some will also allow linkage specifiers for Fortran, Pascal, or BASIC.
(You will need to check the documentation for your compiler.)
This program causes myCfunc( ) to be linked as a C function.
#include <iostream> using namespace std;
Stáhnout
Reklama