当前位置:网站首页>Precautions for using C language global variables (global variables in C and H files, static global variables)
Precautions for using C language global variables (global variables in C and H files, static global variables)
2022-06-28 04:41:00 【Dontla】
C Language contains global variables in header files in three forms :
1 Declare a global variable in the header file , In a C Global variables are defined in the file , And then in all the references to this header file C The global variable value can be used in the file .
If in main.c Definition
int a = 3;
Then define a main.h, Then all references main.h Of c In file , All accessible a And change its value .
2 Define a static global variable in the header file . Then all references to the header file C file , Each has a static global variable with the same name whose scope is within the scope of this file . The variable in different files has the same name , But it's a different variable .
For example a.h In the definition of
static int a = 3;
So in a.c I quote a.h, And will a Value is modified to 4.
stay b.c Also quoted in a.h, incorrect a Value to modify , Print a value , Still 3, Not because a.c To change the value .
3 Define global variables in the header file . This header file can only be used by one C File reference once .
such as a.h In the definition of
int a = 3;
stay a.c Reference can be made to a.h, Also on a Access and modify .
If there are under the same project b.c Refer to the a.h, The compiler will report the error of global variable with the same name when linking , Resulting in compilation failure .
Reference article :c The language header file contains 、 Use of global variables
边栏推荐
- How to clean the nozzle of Epson l3153 printer
- What is the level 3 password complexity of ISO? How often is it replaced?
- 代码理解:IMPROVING CONVOLUTIONAL MODELS FOR HANDWRITTEN TEXT RECOGNITION
- Analyse complète annuelle du marché chinois de l'audio en 2022
- Multithreading and high concurrency V: detailed explanation of wait queue, executor and thread pool (key)
- 【Matlab BP回归预测】GA优化BP回归预测(含优化前的对比)【含源码 1901期】
- Multithreading and high concurrency III: AQS underlying source code analysis and implementation classes
- Bitlock recovery occurs in win 10, and the blue screen error code is 0x1600007e
- CDC全量抽取mysql数据时,怎么才能加快ChunkSplitter呢?
- 华为9年经验的软件测试总监工作感悟—写给还在迷茫的朋友
猜你喜欢
随机推荐
Necessary skills for test and development: actual combat of security test vulnerability shooting range
Analyse complète annuelle du marché chinois de l'audio en 2022
Design a stack with getmin function
Multithreading and high concurrency III: AQS underlying source code analysis and implementation classes
政策利好,20多省市开启元宇宙发展规划
【Matlab红绿灯识别】红绿灯识别【含GUI源码 1908期】
Secouer le son et se battre ~ prêter attention au blogueur
Uncover the mystery of SSL and learn how to protect data with SSL
Reading notes of top performance version 2 (II) -- Performance observation tool
leetcode - 329. Longest increasing path in matrix
From meeting a big guy to becoming a big guy, shengteng AI developer creation day brings infinite possibilities to developers
The company leader said that if the personal code exceeds 10 bugs, he will be dismissed. What is the experience?
11_ Deliberate practice and elaboration
The second round of free public classes of the red team is coming ~ 8:00 tomorrow night!
Introduction to SQLSERVER database
抖音实战~取关博主
有大佬出现过mysql cdc用 datastream时,出现重复binlog消息的情况吗
[MySQL] multi table connection query
10:00面试,10:02就出来了 ,问的实在是太...
Bitlock recovery occurs in win 10, and the blue screen error code is 0x1600007e









