About 1,660,000 results
Open links in new tab
  1. c - Global variables in header file - Stack Overflow

    Nov 13, 2011 · 15 You should not define global variables in header files. You can declare them as extern in header file and define them in a .c source file. (Note: In C, int i; is a tentative …

  2. How to Declare a Global Variable in C++? - GeeksforGeeks

    Jul 23, 2025 · In C++, global variables are like normal variables but are declared outside of all functions and are accessible by all parts of the function. In this article, we will learn how to …

  3. C code - declaring global variable - Microsoft Q&A

    May 12, 2023 · I have a legacy code: // file3.h extern int g_index; // file3.c int g_index= -1; // file1.c g index = some_value; Compiles and works fine. But, the quality tools says: Don't use extern …

  4. Initialization Of Global Variables In Header File – ZJDGHM

    Aug 3, 2025 · In C++, global variables are like normal variables but are declared outside of all functions and are accessible by all parts of the function. In this article, we will learn how to …

  5. 7.10 — Sharing global constants across multiple files (using ...

    Dec 14, 2024 · Downsides: Changing anything in the header file requires recompiling files including the header. Each translation unit including the header gets its own copy of the …

  6. Inline Variables in C++17: ODR-Safe Header Definitions

    Jun 19, 2025 · Introduction C++17 introduced inline variables, a feature designed to address a long-standing challenge in C++: defining variables in header files without violating the One …

  7. C vs C++ global variable in header - Stack Overflow

    Mar 28, 2019 · I know that global variables should not be defined in a header and that we should instead use extern to only declare them in the header. But I've tried nonetheless to define a …

  8. Why Do Static Global Variables in Header Files Cause ...

    Nov 28, 2025 · If you’ve ever worked on a C++ project with multiple source files, you’ve likely encountered perplexing linker errors or unexpected runtime behavior related to global …