Tuesday 19 March 2013

Keywords in C/C++(Microsoft Specific)

There are some microsoft specific keywords used in C/C++.We need to know about their characteristic which are following:-

(1)_asm:-The _asm keyword invokes the inline assembler can appear wherever a C or C++ statement is legal .It cannot appear by itself.It must be followed by an assembly instruction ,a group of instructions enclosed in braces or at the very least an empty pair of braces .

Ex:-

__asm {
       mov al, 2
       mov dx, 0xD007
       out dx, al 
       } 
(2)dllimport:-It is used to import function ,data from the dll.It is used with _declspec keyword.

(3)_int8:-It is a integer of 8-bit.It is synonymous to char.

(4) naked:-For the function declared with the naked attribute ,the compiler generates code without prolog and apilog code.Naked functions are particularly useful in writing virtual device driver.The naked code is only valid on x86 and is not available on x64 or itanium.
Ex:-


__declspec( naked ) int func( formal_parameters ) {}



(5)_based:-_based keyword allows us to declare pointer based on pointers .The _based keyword has limited uses 32-bit and 64-bit target compilations.
Ex:-



type __based( base ) declarator


(6)_except:-It is used in a try-except statement._except is used as an exception handler.

(7)_int16:-It is a 16 bit integer and synonymous to  the short.

(8)_stdcall:-stdcall calling convention is used to call Win32 API functions .In this calling convention callee
cleans the stack ,so the compiler makes vararg functions _cdecl .Functions that uses this calling convention require a function prototype .It pushes parametes on the stack in reverse order means right to left .Function declared  using with the _stdcall modifier returns values the same way as function declare using _cdecl.
Ex:-

return-type __stdcall function-name[(argument-list)]

(9)_cdecl:-decl is the default calling convention in C/C++.In this calling convention the stack is cleaned up by the caller .It creates larger executable than _stdcall because it requires each function call to include stack cleanup code .It pushes parameters on the stack in reverse order means right to left.There is no case translation performed in this calling convention.Underscore caracter(_) is used as prefix to names ,except when exporting _cdecl functions that use C linkage .

Ex:-

int __cdecl system(const char *);

(10)_fastcall:-It specifies that arguments to functions are to be passed in registers ,when possible.Stack clean up is done by callee function .It pushes parameters in reverse order means right to left.There is no case translation is performed in this calling convention.
Ex:-
void FASTCALL DeleteAggrWrapper(void* pWrapper);

(11)_int32:-_int32 is used as 32 bit integer.It is synonymous to type int.
(12)thread:-The thread extended storage class modifier is used to declare a    thread local variable.It is used with _declspec(thread) declarator .
(13)_declspec:-It is a storage class modifier  used with many extended attribute like dllimport and dllexport.
(14)_finally:-_finally is used in try-finally statements.The try-finally statement is a microsoft extension to the C and C++ language that enables target applications to guarantee execution of cleanup code when execution of block of code is interrupted .
(15)_int64:-_int64 is a integer of 64 bit.
(16)_try:-A _try keyword is used in _try-_except,_try-catch,_try-_finally statement to enclose one or more statements that might throw an exception.
(17)dllexport:-dllexport storage class attribute enables us to export function ,data & objects from the dll.Declaring function as dllexport eliminates the need for a module definition file ,at least with respect to the
specification of exported functions .Note that dllexport replaces the _export keyword .If a class is marked declspec (dllexport ),any specialization of class templates in the class hierarchy are implicitly marked as declspec(dllexport ).This means templates are explicitly instantiated and its member must be defined .The declaration of dllexport must use extended attribute syntax and the _declspec keyword.

(18)_inline:-The _inline specifier instructs the compiler to insert a copy of the function body into each place the function is called .
(19) __leave:-The __leave keyword is valid only within the gaurded section of a try-finally statement and its effect is to jump to the end of the guarded section.   




No comments:

Post a Comment