It does not make sense to use extern before the function; extern is used before the variable to indicate that the variable is an external link symbol. (A function is naturally an external link symbol)
-- Related to this, specify the function call style (_ cdecl, _ stdcall, _ fastcall), or generate a dynamic Connection Library (_ declspec (dllimport), _ declspec (dllexport), or specify the compilation language type (C, C ++), all need to be in the Declaration body (. h file), do not need to be in the implementation body (. c file.
Static also has different meanings for functions and variables.
Non-portable memory allocation techniques: (continuous allocation is required for the implementation of the Platform's malloc library. Purpose: Summary access and implicit storage)
Struct name {
Int namelen;
Char namestr [1];
};
# Include <stdlib. h>
# Include <string. h>
Struct name * makename (char * newname)
{
Struct name * ret = malloc (sizeof (struct name)-1 + strlen (newname) + 1 );
If (ret! = NULL ){
Ret-> namelen = strlen (newname );
Strcpy (ret-> namestr, newname );
}
Return ret;
}
C99 introduces many existing features in C ++: struct is getting more and more like a class-you can create unknown temporary struct variables.
The sizeof value of the struct is the memory usage range, and the "empty" value is also included.
How to calculate the byte offset of field in struct?
Non-portable solution: # define offsetof (struct, f) (size_t) (char *) (struct *) 0-> f-(char *) (struct *) 0)
Do not use the built-in = or! = To compare struct variables -- compiler alignment operations may result in sparse structs and holes
How do I input a constant where the pointer type is required?
For example, how do I input a constant in the intf (int *) function? -- In C99, you can use "Compound literal quantity": f (int []) {5}); similar to Java ??
A function name is essentially an address, similar to an array name. A function pointer is essentially a variable that can be used in assignments and arithmetic operations. () Is the only suffix operator that can be used for function pointers.
The difference is that the address of the function name and function pointer is actually the address of the Code area or ROM, while the address of the Data variable name and Data Pointer is actually the address of the RAM in the data area, the two cannot be universal. For example, the null function pointer is void (*) (), and the NULL data variable pointer is void *;
NULL is not much effort-type conversion is still required when function parameters are passed in.
In general, NULL is just a prompt: Here is a pointer 0, no other meaning. Therefore, do not use a pointer (such as an ASCII null character.
Rules:
1. When NULL pointer constants are required, using 0 or NULL is equivalent;
2. Add forced conversion before 0 or NULL according to the prototype when 0 is passed in the function call;
Why do we need NULL? Because NULL (NULL pointer) is implemented as 0 on some platforms, and special values are used for implementation on other platforms-why is the C standard not uniformly defined as 0? Because Automatic hardware traps are triggered by special values on some platforms, the error of unauthorized access to null pointers can be captured. It is unfortunate to use zero to implement null pointers.
An array is not a level-1 element in C language, and a subscript is not a level-1 operator. It is defined on the basis of pointer arithmetic operations. Therefore, a [I] is equivalent to * (a) + (I )), it is also equivalent to I [a].
By defining the pointer p for different types (mainly dimensions) and associating array a, you can perform ++ or -- overloading at different granularities on p.
A c language exercise Compilation:
C Programming FAQs, Steve Summit, China Post and Telecommunications 2008