Questions tagged [extern]

extern is an access-specifier in C and C++ which defines a global variable that is visible to all object modules.

The extern keyword means "declare without defining". In other words, it is a way to explicitly declare a variable, or to force a declaration without a definition. The extern declaration in C/C++ is to indicate the existence of, and the type of, a global variable or function. A global variable, or a global function, is one that is available to all C/C++ modules. An extern is something that is defined externally to the current module.

schematic representation of global variable declared with extern keyword (source)

1475 questions
-3
votes
1 answer

How to use extern for declaring/defining global variable in C++ and CUDA

I have the following code structure composed of one .cpp, one .cu and one .hxx UTILITIES.hxx #ifndef UTILITIES_HXX #define UTILITIES_HXX namespace B{ extern int doors; } FILE2.cu #include "utilities.hxx" namespace A { int foo (){ …
alvarella
  • 81
  • 3
-3
votes
1 answer

Output duplicated and corrupt?

I am trying to load a C++ DLL in a C# program, however the variables from C++ when loaded in C# are corrupt (I think) This is how the output should look like (this is C++) //cout << "Loading config, please wait..." << endl; LoadConfig(); …
EngineEye
  • 11
  • 7
-3
votes
2 answers

How to share global variables between files in Python like C

i have 2 files #foo.py global x def foo(): x = 8 #main.py from conf import * if __name__ == "__main__": foo() how to get the X value in main.py file i have to use only 2 files here now if print or store x to other variable it has to…
-3
votes
1 answer

Is it possible to define constants in C at runtime?

I have a file, file1.c, where I would like to define some constants if some requirements are met, to be used in an other file, file3.c. file1.c: #include "header.h" int set_constants(void) { #ifdef EXAMPLE_MACRO int fd, status, size; fd =…
LukesDiner
  • 145
  • 8
-3
votes
3 answers

can I make functions with unresolved dependency in C?

what is the SHORTEST or Easiest way to solve the following dependency problem. Given, I have to keep xx in a separate file. file1.h static inline void xx(){ yy();//yy is not defined in this file but defined in file2.c; } file2.c …
sapy
  • 8,952
  • 7
  • 49
  • 60
-3
votes
1 answer

Function in c++ with extern keyword

I am going through a source code and I found these snippets extern int main(); main(); and one more is extern void create_network_device(int N, const char* route, const char* ip); create_network_device(0, "10.0.0.0/24", "10.0.0.1"); What is…
karra
  • 45
  • 1
  • 10
-3
votes
1 answer

Extern keyword issue in c

extern int i; void add(); int main() { add(); if (i == 0) printf("scope rules\n"); } void add() { int i; } I getting error in this case even variable i is defined in add function but it will give no build errors in following…
ravi
  • 63
  • 1
  • 8
-3
votes
2 answers

Declaring extern array in another module in C

Writing a logging system and I just want an array to be stored and modified in a module (let's call it foo.c, with an appropriately-named header file foo.h) while being able to access it's contents in main.c. In foo.c I have: unsigned char log[4096]…
Justin
  • 33
  • 1
  • 6
-3
votes
1 answer

Extern variables C++

I have a struct that I want to fill out in a separate source file from where I am running main. In the header file I included the extern but when I go to define the variable in a source file it doesn't work. //This is a header file struct…
Hippity Hoopla
  • 68
  • 1
  • 10
-3
votes
1 answer

Why the result doesn't write on the text file?

I have created csis.txt file but when I look up, it is empty. Could anyone teach me why the file is created without results? Here are my codes: //ZipCode.cpp #include #include "ZipCode.h" #include #include #include…
-3
votes
2 answers

How to use variables across class files in C++?

I need to use variables I assign in one class into another. For example I have this bit of code. This is CharacterCreation.h followed by CharacterCreation.cpp #ifndef CHARACTERCREATION_H #define CHARACTERCREATION_H class…
Adyn_G
  • 7
  • 3
-4
votes
1 answer

Use of struct from ".h" file

Say I have a header file file which contains a struct. Struct aa { int a; int b; }; In a.c file I include that header file and I do struct aa first; and then use first.a and first.b to make changes. In b.c file I include that header file…
bbcbbc1
  • 95
  • 7
-4
votes
2 answers

Why is the storage class of global variables in C implicitly defined as "extern"?

When we declare any global variable, for instance int x; it is equivalent to extern int x; Now by default global variables are initialized to 0 by the compiler, which means they are allocated memory. But if I simply write extern int x; then…
Radha Gogia
  • 765
  • 1
  • 11
  • 22
-5
votes
1 answer

Array declared without size and const volatile

I found this line in my work project, but I can't understand this: extern const volatile uint8 * const volatile array[]; Could you please help me explain the line?
-5
votes
1 answer

send a variable value to another file

I would like to send a value of a Boolean from file B.cc to A.cc, where A.cc is executed before B.cc for the next cycle of operation. I have the boolean value as an extern volatile and as a global variable. How do I save the value till the next…
Charan Karthikeyan
  • 57
  • 1
  • 2
  • 12
1 2 3
98
99