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
-2
votes
2 answers

Can I access a union in my source.c from main.c in PIC C18?

I am in a position in which I have got an anonymous structure containing several elements. In order to access them by index I have placed them in a union, like this: union { struct { unsigned char COMMAND; //STRUCT_ARRAY[0] …
hat
  • 781
  • 2
  • 14
  • 25
-2
votes
1 answer

Compiler error using global variables 'extern' in header files in C++

I'm using the Java Native Interface and trying to make the JNIEnv environment pointer (*env) a global variable. I'm using eclipse with g++ and I have the following files: CustomLibrary.hh #ifndef CUSTOMLIBRARY_HH_ #define CUSTOMLIBRARY_HH_ #include…
-2
votes
3 answers

Linking against a local `extern` variable

I reckon this has been probably answered before. Please mark as a duplicate if it has! I'm having trouble understanding what extern means for local variables (or local functions!). I can't seem to see how it is functionally different from a static…
Alec
  • 31,829
  • 7
  • 67
  • 114
-2
votes
1 answer

Use of "EXTERN" Keyword in header file while its definition in source file

I am new to C programming and was attempting to write a code in which values of variables x and y are taken from the user in the main function of File1.c. All other functions in the file use the value of these variables. I have used 'extern' keyword…
rdx1994
  • 7
  • 2
-2
votes
1 answer

the memory location of static and extern storage class in C

I have two files which are sharing the global variables. In main.c #include static int b; extern int b; main() { extern int a; printf("a=%d &a:%p\n",a,&a); printf("b=%d &b:%p\n",b,&b); fn(); } In fun.c #include int b=25; int…
GShaik
  • 197
  • 1
  • 17
-2
votes
2 answers

Extern syntax in C?

I am slightly confused about using "extern" in my c code, when there is a global variable involved. I tried the following, and got a compilation error: Main.c: extern unsigned short *videobuffer; //I also tried this in a separate and it failed with…
Shanty
  • 101
  • 8
-2
votes
1 answer

I'm getting an error when I try to use extern to have variables across multiple source files

EDIT: I forgot to use the std namespace. That fixed some errors but not all. I'm making a text-based game. Originally, the game was in one, main source file. Now, for ease of navigation (the game is open-sourced, and I'm trying to encourage…
-2
votes
1 answer

Why should I use "extern" for function declaration in C?

I was wondering if there is any difference if skip extern storage class specifier while declaring a function? Specifically, is there any difference between following two? void foo (); and extern void foo();
username_4567
  • 4,737
  • 12
  • 56
  • 92
-2
votes
1 answer

Objective C Global Variable

Can anyone tell me where I'm going wrong here please. I have created an NSobject called BeaconData. The header file is: #import #import #import @interface…
Mike
  • 35
  • 5
-2
votes
1 answer

What does extern mean in an obj-c header

what does this code mean? // myheader.h extern const NSUInteger Something; @interface MyObject : NSObject ... @end What does extern mean here, and how can/will it be used? is it part of the object? is it global in the project? Does it matter…
Nick Ginanto
  • 31,090
  • 47
  • 134
  • 244
-2
votes
1 answer

error LNK2001: unresolved external symbol "class"

I've a header file having a "extern class definition" in it. Both these header file and class are in different C++ assembly. Now there is a class in different C++ assembly which is trying to access this "extern" class functions but there are all…
Bobby
  • 169
  • 1
  • 2
  • 9
-2
votes
3 answers

using "extern" cannot find variables in other files when they are static or in namespaces

I listed my two questions below with C++ code. Thank you in advance. (1) Using "extern" fails to find outside static symbols. Why? config.cpp static int config_id = 123; run.cpp extern int config_id; void exec() { int id = config_id; //…
lichgo
  • 523
  • 1
  • 6
  • 16
-2
votes
2 answers

C++ does not name a type in use of classes

I want to modify object "t1" of the class "abc" in "update" function which is defined in different file(temp2.cpp) than where "t1" is defined(temp1.cpp). I tried to use extern but that resulted in error. Please suggest nice way of doing this. …
K_D
  • 1
  • 2
-2
votes
2 answers

AJAX post to external url

I am trying to post data with ajax to an external url with the following code: $(document).ready(function(){ $('.submit_button').click(function() { $.ajax({ type : 'POST', url :…
Daniil
  • 43
  • 1
  • 1
  • 8
-2
votes
1 answer

C++: declaring an extern vector container in header file causes errors

I tried searching for solution but couldn't find. So I have a header file items.h: #ifndef ITEMS_H #define ITEMS_H #include using std::vector; int create_item(); class itemClass { public: short int xTile; short int yTile; …
Aske
  • 11
  • 1
  • 5