Is a header file a translation unit? If I add the static keyword to a variable in a header file, could I call that variable in my .c or .cpp file? Thanks.
Is a header file a translation unit?
671 Views Asked by Serket At
2
There are 2 best solutions below
0
HolyBlackCat
On
No, headers are not separate translation units.
Each .c/.cpp file is a separate translation unit, and since preprocessor textually replaces #includes with the contents of the headers, code from all headers included (directly or indirectly) by a .c/.cpp file is a part of that file's translation unit.
In other words, a translation unit is a .c or .cpp file after preprocessing.
Related Questions in C++
- How to immediately apply DISPLAYCONFIG_SCALING display scaling mode with SetDisplayConfig and DISPLAYCONFIG_PATH_TARGET_INFO
- Why can't I use templates members in its specialization?
- How to fix "Access violation executing location" when using GLFW and GLAD
- Dynamic array of structures in C++/ cannot fill a dynamic array of doubles in structure from dynamic array of structures
- How do I apply the interface concept with the base-class in design?
- File refuses to compile std::erase() even if using -std=g++23
- How can I do a successful map when the number of elements to be mapped is not consistent in Thrust C++
- Can std::bit_cast be applied to an empty object?
- Unexpected inter-thread happens-before relationships from relaxed memory ordering
- How i can move element of dynamic vector in argument of function push_back for dynamic vector
- Brick Breaker Ball Bounce
- Thread-safe lock-free min where both operands can change c++
- Watchdog Timer Reset on ESP32 using Webservers
- How to solve compiler error: no matching function for call to 'dmhFS::dmhFS()' in my case?
- Conda CMAKE CXX Compiler error while compiling Pytorch
Related Questions in C
- How to call a C language function from x86 assembly code?
- What does: "char *argv[]" mean?
- User input sanitization program, which takes a specific amount of arguments and passes the execution to a bash script
- How to crop a BMP image in half using C
- How can I get the difference in minutes between two dates and hours?
- Why will this code compile although it defines two variables with the same name?
- Compiling eBPF program in Docker fails due to missing '__u64' type
- Why can't I use the file pointer after the first read attempt fails?
- #include Header files in C with definition too
- OpenCV2 on CLion
- What is causing the store latency in this program?
- How to refer to the filepath of test data in test sourcecode?
- 9 Digit Addresses in Hexadecimal System in MacOS
- My server TCP doesn't receive messages from the client in C
- Printing the characters obtained from the array s using printf?
Related Questions in FILE
- Helpt with reading files
- Why can't I use the file pointer after the first read attempt fails?
- Can't read the file using std::wifstream C++
- How can the scanner reread the entire file after it has already executed hasNextLine once?
- What is 'Invalid Load Key, '\x00'
- php $_FILE variable undefined index
- Data loaded from the file is not returned in the correct order
- File splitting and encryption
- Optimizing an s5cmd command that uses awk to generate a text file
- segmentation fault while reading in text file ( c++ )
- File.OpenText is adding C:\ to the front which is an error
- UTF-8 issue with excel
- How to upload files to MediaWiki APIs in Rust?
- No such file or directory: '/tmp/tmp_ejr26m6.upload.mp3' in Django
- Problems accessing zip files on the react front end from express backend
Related Questions in HEADER-FILES
- C++ - Unknown type name
- Unable to install old gcc version on Mac using homebrew. Error in make possibly due to incorrect header file version
- External macro definition in header
- How to create your own C++ Library and share it with others so that everyone can use it?
- White space to the right side of my header/navbar
- How C ++ header files hold the cpp respective file definitions if they do not include them on themselves?
- Trying to render texture but I can't pass the variable to draw function
- Question about header files and functions in separate files in C++
- Visual Studio Additional Include Directories
- Initializing a large map in header cause g++ crashes
- Umbrella-Header uses wrong import syntax after `pod install`
- The game module "project name "could not be loaded. There may be an operating system error or module may not be properly setup
- Why does it throws an error while putting functions into header in VSCode but not GCC?
- Why net/if.h before ifaddrs.h?
- Error about the Redefinition of a struct and conflicting types for a function
Related Questions in TRANSLATION-UNIT
- Prevent c++ template codes from being compiled for many times
- Is a Translation Unit always a file?
- How to avoid deferring the initialization of static storage duration variables?
- How can static local variable shared along different translation unit?
- ODR and C++ Versioning for Shared Library Wrapper
- Is a translation unit valid C++? And is a translation unit (for GCC) the output of g++ -E?
- Is there any reason I should include a header in the associated cpp file if the former only provides declarations the latter defines?
- How to have TU-specific function template instantiation?
- constexpr function which is shared in multiple modules
- How a multiple times #included guarded header file will be inside different translation units?
- How many translation units in one module?
- Translation unit when including a source file?
- Why the weak symbol defined in the same .a file but different .o file is not used as fall back?
- Including multiple .c files in a single translation unit
- Does `#pragma GCC system_header` in a header file extend into another source or header file that includes it?
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
No, a translation unit is the full output of the preprocessor. A header file will be included and its content may become a part of the translation unit.