We cover below parts.
- External variable
- Static variables
- Register variable
- The C preprocessor
Other parts(basics of fuctions, header rules, block structure, initialization and recursion) are skipped.
1. External variable
A variable is external if it is defined outside of any function. When we need to inform other source files about functions/global variables in a file. For functions, put function prototypes in header file. For variables, re-declare the global variable using the extern keyword in header file. extern informs compiler that variable defined somewhere else. extern helps to access/modify of global variable from other source files.
2. Variable scope (static variables and register variables)
scope - defines the region in which a variable is valid.
static keyword has two meanings, depending on where the static variable is declared. Outside a function, static variables/functions only visible within that file, not globally (cannot be extern’ed). Inside a function, static variables have following characteristics. First, they are still local to that function. Second, they are initialized only during program initialization. Third, they do not get reinitialized with each function call.
During execution, data processed in registers. Explicitly storing commonly used data in registers helps to minimize load/store overhead. We can explicitly declare certain variables as registers using register keyword. Registers do not reside in addressed memory; pointer of a register variable illegal.
Check more detailed about rule scope in below links.
https://www.tutorialspoint.com/cprogramming/c_scope_rules.htm
http://www.geeksforgeeks.org/scope-rules-in-c/
Static variable
http://quiz.geeksforgeeks.org/static-variables-in-c/
Register variable
http://www.geeksforgeeks.org/understanding-register-keyword/
3. The C Preprocessor
Check below link for a clearly overview on CPP.
https://gcc.gnu.org/onlinedocs/cpp/
Không có nhận xét nào:
Đăng nhận xét