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

    Nov 13, 2011 · 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 definition, it allocates …

  2. headers - How do I share a variable between source files in C ...

    I know that global variables in C sometimes have the extern keyword. What is an extern variable? What is the declaration like? What is its scope? This is related to sharing variables across source...

  3. 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 variable. Global constants …

  4. Global Variables in C - GeeksforGeeks

    Jul 23, 2025 · Prerequisite: Variables in C In a programming language, each variable has a particular scope attached to them. The scope is either local or global. This article will go through global …

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

    May 12, 2023 · C code - declaring global variable Flaviu_ 1,091 May 12, 2023, 9:02 AM I have a legacy code: // file3.h extern int g_index; // file3.c int g_index= -1; // file1.c g index = some_value; Compiles …

  6. cs.emory.edu

    How to organize the global variables in a multi-files C program The global variables in a multi-files C program are organized as follows: Each global variable must be defined inside exactly one of the …

  7. c - Variable declaration in a header file - Stack Overflow

    In case I have a variable that may be used in several sources - is it a good practice to declare it in a header? or is it better to declare it in a .c file and use extern in other files?

  8. Variables in header file - what's that all about? | Pirate ...

    This statement (with or without optimizations done by the compiler) copies the entire code in the header file myheader.h into the source file where the header is included. Hence when a header file …