In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the relevant knowledge of "how to use the keyword static of CAccord +". The editor shows you the operation process through an actual case. The method of operation is simple and fast, and it is practical. I hope that this article "how to use the keyword static of CAccord +" can help you solve the problem.
Demonstration of hidden scenes in C language
When we compile multiple files at the same time, all global variables and functions without the static prefix have global visibility. Causes the symbol table to think that there is a collision between a global variable and a function with the same name.
Scenario: global variables / functions are owned in multiple .cc files in .h and are globally visible with link problems.
A.h
# pragma once#includevoid Test () {printf ("I am test..\ n");}
B.c
# include "a.h" void call () {Test ();}
C.c
# include "a.h" int main () {Test ();}
Makefile
All:cc:c.o b.o gcc-o $@ $^ c.o:c.c gcc-c $^ b.o:b.c gcc-c $^ .PHONY: cleanclean: rm-rf * .o c
Running result
At this point, view the b.o and c.o symbol tables. (readelf-s xxx.o)
You can see that both parties'.o symbol tables think that there is a Test of a GLOBAL global function, and the symbol tables formed in the assembly phase of the two sides will have a conflict of global functions with the same name at the summary stage.
At this point, both binaries are considered to have the Test () function, and both are global. Global functions can only have one name (note: overloading is renamed at the bottom). Although we know that the two Test () are the same, link thinks that there are two functions with the same name implemented, so an link error is reported.
Solution method
Separation of declaration and definition
Get into the habit of separating declaration from definition, and only declare no definition in .h. Defined in the .c file.
A.h
# includevoid Test ()
A.c
# include "a.h" void Test () {cout
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.