想必很多學C++的都沒聽說過內在函數,我也是初次聽見。什麼是內在函數?英文是Intrinsic Function。這是一種編譯器特殊函數,它的行為類似與C++的內嵌函式,但是由於它是編譯器提供的,所以編譯器對其更加瞭解更利於最佳化。比如說memcpy等就是內在函數。如果編譯器有選擇/Optimization,那麼編譯器在產生代碼的時候將直接插入運行代碼而不是調用該函數,這和內嵌函式差不多,但是如上所說,由於編譯器對其的瞭解,這個最佳化會更好。
在vc++中,AbnormalTermination也是一個內在函數。
下面是維基百科的一些介紹:
This article is about compiler intrinsic functions. For X toolkit, see Intrinsics.
In compiler theory, an intrinsic function is a function available in a given language whose implementation is handled specially by the compiler. Typically, it substitutes a sequence of automatically-generated instructions for the original function call, similar to an inline function. Unlike an inline function though, the compiler has an intimate knowledge of the intrinsic function and can therefore better integrate it and optimize it for the situation. This is also called builtin function in many languages.
Compilers that implement intrinsic functions generally enable them only when the user has requested optimization, falling back to a default implementation provided by the language runtime environment otherwise.
Intrinsic functions are often used to explicitly implement vectorization and parallelization in languages which do not address such constructs. Altivec and OpenMP are examples of APIs which use intrinsic functions to declare, respectively, vectorizable and multiprocessor-aware operations during compilation. The compiler parses the intrinsic functions and converts them into vector math or multiprocessing object code appropriate for the target platform.
Microsoft and Intel's C/C++ compilers as well as GCC implement intrinsics that map directly to the x86 SIMD instructions (MMX, SSE, SSE2, SSE3, SSSE3, SSE4). In the latest version of the Microsoft compiler (VC2005 as well as VC2008) inline assembly is not available when compiling for 64 bit Windows, therefore intrinsics are necessary. To compensate for the lack of inline assembly, new intrinsics have been added that map to standard assembly instructions that are not normally accessible through C/C++ (e.g.: bit scan).