The gcc compiler has powerful functions and supports very flexible syntax, which brings great convenience to programming and difficulty to code porting.
1. Declare the 64-Bit Data Type:
Gcc: long
Vc: _ int64
2 case statement in switch Syntax:
Gcc: case '0'... '9'
Vc: case 0:
Case1:
...
3. Range of register variables:
Gcc: You can declare the register variable as global or local
Vc: only local variables are allowed.
4. Signed and unsigned shaping:
Gcc: Add LL or ULL to the constant number, for example:
Unsigned: 0 xffffffffffffffull
Signed: 0 xffffffffffffffffLL
Vc: Increase the conversion before the constant number. For example:
Unsigned: (uint64_t) 0 xffffffffffffffff
5 macro variable parameters
Gcc: # define AAA (x ...)
Vc: not supported. When such a problem is encountered, it can only be divided into several macros based on the actual situation of code analysis.
6. initialize the specified Element in the array:
Gcc: static int array [1, 100] = {
[10] = 10,/* array [10] = 10 ;*/
[20] = 20,/* array [20] = 20 ;*/
}
Function: In this method, the value of the specified element can be initialized in the array declaration. Except for arrar [10] and array [20], other elements are automatically initialized to the default value, this gives us a very simple method. Is this function cool?
Vc: not supported. It can only be implemented by filling 0 before and after the specified element or writing an initialization function. For example, you can write the initialization function as follows:
Void init_array ()
{
Array [10] = 10;
Array [20] = 20;
}
7. Structure alignment:
First, explain the meanings of the following attribute keywords:
1. Attribute packed: used for variables and types. It indicates the minimum possible alignment for variables or structure fields. For enumeration, structure, or union types, it indicates that this type uses the smallest memory.
2 attribute aligned: used for variables, structures, or union types. It specifies the aligned quantity of variables, structure fields, structures, or unions, in bytes.
3 attribute noreturn: used for functions, indicating that the function is never returned. This allows the compiler to generate slightly optimized code. The most important thing is to eliminate unnecessary warning information, such as the variable that is not initially optimized.
4 attribute unused: used for functions and variables, indicating that the function or variable may not be used. This attribute can prevent the compiler from generating warning information.
These keywords correspond to each other in gcc and vc, but they are used differently. Note: vc must be installed with a service pack patch before it is supported.
Gcc:
Struct _ attribute _ (packed) st_syment
{
...
}
Vc:
# Pragma pack (push, 1)
Struct st_syment
{
...
}
# Pragma pack (pop)
Indicates that the elements in this struct are aligned by byte.
Gcc: _ attribute _ (aligned (16 )))
Vc: _ declspec (align (16 ))
Indicates that the struct instance is 16 bytes aligned when it is created.
Gcc: _ attribute (noreturn ))
Vc: _ declspec (noreturn)
This function does not need to be returned.
8. Obtain the return address of the current function, that is, the next instruction address of the function called. For example:
Push edx
Call _ func/* call the function named func */
Pop edx
In the func () function, there is another statement:
Void func ()
{
...
Retaddr = _ builtin_return_address (0);/* after this statement is executed, the retaddr value should be the address of the pop edx command above */
...
}
Gcc: retaddr = _ builtin_return_address (0)
Vc: _ asm {mov eax, [ebp + 4]}
_ Asm {mov retaddr, eax}
We know that when the cpu executes a command, the eip always points to the next command address. Before calling a function, the eip is first put into the stack, so that the function can continue executing the subsequent commands after returning the result. That is to say, before entering the function, the value of the top stack (esp) is eip, so we can solve this problem based on this idea. In the Assembly Code generated after vc compilation, each function header has two commands:
Push ebp
Mov ebp, esp
Put the original esp into ebp, add the previous push ebp, and the order of stack pressure is from high to low, therefore, [ebp + 4] is equivalent to the eip before the function is called.