C++ instance resolution of pointer to function
- 2020-04-02 02:26:59
- OfStack
C++ function Pointers are generally Pointers to functions, not to objects. Just like any other pointer, a function pointer points to a particular type. The function type is determined by its return type and the parameter list, regardless of the function name.
Definition:
char ( *fP ) ( char . int ) ;
Assignment:
char function(char i . int j)
{
}
Fp = function;
call
(* fp) (10100);
type char (*FUN)(char . int);//The type definition
FUN fp ;//Define fp as a pointer to a function
The use and action of volatile :
Const is the opposite of volatile,
Volatile means that the value in the memory can change at any time.
uchar a . b . c
a=5;
b=a; //b=5
c=a; //c=5
volatile uchar a . b . c
a=5;
b=a; //B not sure
c=a; //C not sure
For example, the P0 port of SCM is initialized as:
P0=0x0000 0001
a=p0; //If the P0 port is artificially connected to a high level, a=0x1111 1111 instead of 0x0000 0001. hardware-related
Volatile is often used when defining the address of a register:
#define rGPCCON (*(volatile unsigned *)0x56000020)
#define rGPCDAT (*(volatile unsigned *)0x56000024)
In a project with a large number of files, minimize the use of global variables and use the function call form directly
Single file: static char I; Define static variables to prevent unexpected changes to the values of variables by other files.
char fun(void)
{
return(i);
}
Directly call the global variable form: extern int I; Such a disadvantage is that there is a hidden danger, when the file is more likely to appear the global variable name problem, at this time to modify the words may be more trouble.