There are many places in C/C++ language where extern is used. However, if you don't really understand its meaning, it will cause great trouble to programming. In order to help you avoid detours, we will explain it in detail.
For smaller programs, there is usually only one C file and one header file. We usually define global variables directly in the C file, and add the int i definition before the program. If you want to define it in the header file, there are two ways: use extern to declare: extern int i; This sentence only declares the variable i. Int i must be added before the C file program to define it. extern int i=0; This sentence does both declaration and definition.
For larger programs, there are many C files and header files. At this time, global variables must be declared in the header file (no initialization is required), and then defined in a C file (the initialized ones must be initialized). If defined in the header file, there will be a duplicate definition error when compiling. If it is only declared in the header file, there will be a warning that there is no definition.
*** ERROR L104: MULTIPLE PUBLIC DEFINITIONS
SYMBOL: K
MODULE: 222.obj (222)
The above error occurs because the variable k is defined repeatedly. Add extern before the variable definition in your header file (it is just a variable declaration without initialization), and then define it before a program that calls a C file of the variable (note that the first C file called is responsible for initializing the variable, and other C files that call do not need the initialization process)
Keywords:KEIL
Reference address:KEILC51 compilation problem ERROR L104
For smaller programs, there is usually only one C file and one header file. We usually define global variables directly in the C file, and add the int i definition before the program. If you want to define it in the header file, there are two ways: use extern to declare: extern int i; This sentence only declares the variable i. Int i must be added before the C file program to define it. extern int i=0; This sentence does both declaration and definition.
For larger programs, there are many C files and header files. At this time, global variables must be declared in the header file (no initialization is required), and then defined in a C file (the initialized ones must be initialized). If defined in the header file, there will be a duplicate definition error when compiling. If it is only declared in the header file, there will be a warning that there is no definition.
*** ERROR L104: MULTIPLE PUBLIC DEFINITIONS
SYMBOL: K
MODULE: 222.obj (222)
The above error occurs because the variable k is defined repeatedly. Add extern before the variable definition in your header file (it is just a variable declaration without initialization), and then define it before a program that calls a C file of the variable (note that the first C file called is responsible for initializing the variable, and other C files that call do not need the initialization process)
Previous article:Combination lock course design
Next article:12864 LCD display pictures
Recommended ReadingLatest update time:2024-11-16 16:37
CS5532 C51 Driver
//The program for CS5532-ASZ
//This is a 24bit ADC and PGIA
//Made by OurWay and 2006/03/21
//#include reg51.h
//#include intrins.h
//Define according to actual situation
//sbit SDI5532 = P2^1;
//sbit SDO5532 = P2^2;
//sbit CLK5532 = P2^3;
//sbit CS5532 = P2^0;
//sbit ACC7 =
[Microcontroller]
OK2440 KEIL bare metal debugging experience
This is my first time to use ARM bare metal debugging. I’m going to record this here for reference by people who encounter the same problem. First, you need to download the corresponding Samsung keil library, which can be found on the legend download page of the keil official website. It is an .exe file and can be i
[Microcontroller]
Keil C51 program crashes when using serial port
When using the serial port of the STC51 microcontroller, sometimes a very strange situation occurs, that is, the program runs dead as soon as it enters. The initialization code is as follows: void UsartConfiguration(unsigned int bps) { SCON = 0X50; //Set to working mode 1 10-bit asynchronous receiver and transmitte
[Microcontroller]
Microcontroller C language tutorial: C51 expression statement and simulator
We have learned most of the basic syntax in the previous section. The syntax of the various basic statements to be learned below can be said to be the soul of the program. In the examples in the previous courses, we have also briefly understood the use of some statements, and we can see that C language is a structur
[Microcontroller]
51 MCU Keil C Delay Program
When using a single-chip microcomputer, you often encounter situations where a short delay is required. The required delay time is very short, usually tens to hundreds of microseconds (us). Sometimes very high precision is also required. For example, when using a single-chip microcomputer to drive a DS18B20, the allow
[Microcontroller]
CXSTM8 parameterless function note
When keil has no parameter function, like, int fun() { int i = 0; return i; } There is no problem with compilation, but in ST's CXSTM8 it needs to be written as int fun(void) { int i = 0; return i; } Can be compiled. Otherwise it will appear #error cpstm8 xxxxxxxxxxxxxxxxx missing prototype
[Microcontroller]
c51: Function
/*
char cabs(char val); // calculate the absolute value of val
int abs(int val);
long labs(long val);
float fabs(float val);
float sqrt(float val);
float exp(float val);
float log(float val);
float log10(floatextefn floatl0510〔float val);
float sin(flaot val);
float cos(flaot val);
float tan(flaot val)
[Microcontroller]
Serial communication between C51 and atmega64 and PROTEUS simulation design
script src="/jf/jf-arcMain-1.js" type=text/javascript /script
script type=text/javascript
/script
script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type=text/javascript /script
script src="http://pagead2.googlesyndication.com/pagead/js/r20110914/r20110914/show_ads_impl.js" /script
[Microcontroller]
- Popular Resources
- Popular amplifiers
- 西门子S7-12001500 PLC SCL语言编程从入门到精通 (北岛李工)
- Siemens Motion Control Technology and Engineering Applications (Tongxue, edited by Wu Xiaojun)
- How to read electrical control circuit diagrams (Classic best-selling books on electronics and electrical engineering) (Zheng Fengyi)
- MCU C language programming and Proteus simulation technology (Xu Aijun)
Recommended Content
Latest Microcontroller Articles
He Limin Column
Microcontroller and Embedded Systems Bible
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
MoreSelected Circuit Diagrams
MorePopular Articles
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
MoreDaily News
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
Guess you like
- What kind of feedback is introduced in the following circuit?
- Storage time of different surface treatment processes for circuit boards
- Upgraded AMG8833 PyGamer thermal imager
- LED Dress
- The relationship between pulse+, pulse- and U2B output is logical AND.
- Southern dumplings and northern dumplings, what do you eat during the Winter Solstice?
- About using the emulator to adjust the STM32 program
- [Intuitive Explanation of Operational Amplifiers] Intuitive animation explains the working principle of operational amplifiers in detail, vivid and easy to understand!
- Need to burn multiple firmwares for mass production? Just rely on this tool!
- SinlinxA33 development board wireless wifi settings