Questions tagged [extern]
extern is an access-specifier in C and C++ which defines a global variable that is visible to all object modules.
1,421
questions
0
votes
1
answer
26
views
C++ Modules - export extern "C" - How to wrap externally linked function in a Module
So basically, I'm writing some WASM/C++ code. For that I'm mainly compiling with:
--target=wasm32-wasi -std=c++2a -flto ... -fmodules -fmodules-ts ...
-mbulk-memory (enables memset/memcpy ...
0
votes
0
answers
30
views
mismatched types expected fn pointer `unsafe extern "system" fn(*mut c_void, *mut c_void) -> HRESULT` found enum `Option<_>`
I'm using the windows crate (Rust For Windows),
And I had a problem:
I'm using a struct that requires a callback, or a handle method.
However, I don't know how to pass a method to that struct, so I ...
0
votes
1
answer
15
views
Extern php file showing up IF radio button true
I want to build a guide where you first choose what kind of recipe you want to create.
The next side I want to show up with the needed further questions:
If you choose drinkA then show content of ...
0
votes
0
answers
30
views
stm32 Run time error caused by Global variable extern const char*
I get a runtime error "Hard Fault" due to the following code:
FileA.c
const char* globalfilepath = "/path/to/folder";
FileB.c
extern const char* globalfilepath;
void my_function(){...
0
votes
0
answers
46
views
C++ equivalent of C99 extern inline __attribute__((always_inline))
Hi,
I read the wiki then I realized "extern inline" is different between C99 and C++.
For example:
foo.cpp
#include <stdio.h>
extern inline __attribute__((always_inline))
void test1(...
-3
votes
1
answer
70
views
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 "...
0
votes
0
answers
27
views
Extern variables aren't initialized [duplicate]
In a project I am doing I use some global variables using "extern" so that all files can access them.
The following is my case:
main.cpp:
#include <iostream>
#include "test.h"...
0
votes
2
answers
54
views
Is there any way to access static global variable defined in main.c and modify it in another file?
For example:
In main.c
static glob_var;
I want to modify the value of glob_var in another file say file1.c
0
votes
0
answers
71
views
How to change the value of a QString global variable in QT?
I'm trying to implement a way for users to change the function of a button that replaces regex matches within text.
As an example input I'm using "(\d\d)/(\d\d)/(\d\d\d\d)|(\d\d)-(\d\d)-(\d\d\d\d)...
0
votes
0
answers
27
views
Assembly - Get extern label address
Extern labels(refers to code or data, does not matter) are labels not found in the current source file and referenced later with the linker. Can I get the address of many extern labels(pointing to ...
0
votes
1
answer
28
views
Extern function pointer variable
One of libraries I use, requires setting an external function:
extern void* req_func(int param);
I have a function with this functionality, defined under another name in another c-file:
void* my_func(...
1
vote
1
answer
43
views
Size of static array initialization in C via contents in define?
There is a similar discussion on Count number of elements for static array initialization in C - but I still cannot tell if all the opportunities in my case are exhausted or not.
Consider the ...
1
vote
1
answer
39
views
I am trying to implement a code using 'extern' keyword, IDE: VS Code (using code runner...) [duplicate]
extrn.c
#include <stdio.h>
extern int var;
int main()
{
printf("%d", var);
return 0;
}
var.c
int var = 5;
I go to file extrn.c and I run the code and I get this:
undefined ...
0
votes
3
answers
74
views
How to declare a function with an unknown parameter datatype in a header file?
I am pretty new to C and have the following issue with a framework specific datatype that is used within an extern declared function for a parameter inside a header file.
//FILE: example.h
extern ...
0
votes
1
answer
36
views
extern keyword with specialized template declaration [duplicate]
I'm working with a code base that has the following declarations in a.cpp:
template <int num_dim = 2>
int register_parameters();
extern template int register_parameters<2>(); // why is ...
0
votes
3
answers
47
views
Can extern make a function variable a global variable?
As I understood extern makes a variable --> global variable, so it means we can also make variable of another function a global variable?
#include <stdio.h>
extern char* name;
void ...
0
votes
0
answers
42
views
How can I add Linux source code global variable?
I face a situation where I need to declare a global variable so every file of Linux source code can reference it. As much as I know, Linux is a Monolithic kernel, so this can be done. So I add the ...
0
votes
1
answer
148
views
extern functions undefined for linux kernel modules
I am developing several kernel modules for linux, below are my module structure:
inc\
shman.h
shman\
extern.c
extern.h
module.c
module.h
...
server\
module.c
module.h
...
0
votes
0
answers
26
views
Using 'extern' inside class gives me 'storage class specified' error [duplicate]
I'm trying to use "Graph" variable globally.
I have no problem defining it in class without 'extern',
but when I add 'extern', it gives following error.
What's wrong and right way to use it?
...
0
votes
0
answers
79
views
Template parameters in extern template
Is it possible to have a template parameter as the template argument in an extern template?
For instance having Bar being extern in the following code
template<typename T>
void Foo() {
Bar&...
0
votes
0
answers
105
views
Error LNK2019: unresolved external symbol C++ and ASM
I ran into this error when trying to run this program that compares the sorting speed of the same array in C++ using both C++ and ASM.
Error Message:
error LNK2019: unresolved external symbol ...
0
votes
1
answer
65
views
What is the correct interpretation of "extern" keyword in C?
In this page I cannot understand why Example 3 throws an error:
// CODE 1:
extern int var;
int main(void)
{
var = 10;
return 0;
}
There are several answers mentioning that var inside main is a ...
0
votes
1
answer
69
views
Extern structure without headers
I have to different files : main.c and source.c. I want to scanf and printf information in main.c file, but to work with structure in source.c. I don't know how to use structure in another file ...
0
votes
0
answers
73
views
Using extern in C for functions
If we have 2 source file and 1 header file of the same name for example
example.c which includes example.h and content is like above:
example.c
#include "example.h"
unsigned int add(...
2
votes
2
answers
91
views
Are functions external by default?
Is a function without a storage class specified in its declaration and definition :
void func(void); // declaration
void func(void) { // implementation
}
be equivalent to the function with ...
0
votes
1
answer
33
views
Does the compiler automatically add an "extern" to a global variable that is not assigned a value in Programe language C? [duplicate]
So far I have understood the following:
A variable declaration is the declaration of a type and name of a variable without allocating memory space for it.
A variable definition means that the variable ...
0
votes
1
answer
29
views
Extern struct builds on aCC (HP-UX) but not on macOS (Xcode)
I have the following headers file that I share across two source files:
sth.h:
#define NBALLS 10
#define NBOTS 2
struct {
float px, py, pz, vx, vy, vz;
}bots[NBOTS];
struct {
float px, py, ...
1
vote
1
answer
96
views
Can I extern the entire namespace?
Is there a method to declare a namespace with the extern modifier so that the namespace's entire content is externally linked?
1
vote
1
answer
65
views
How to put all c-functions from .dll into a c++ class?
I need to write a wrapper-class to use the functionality of one of the C-library, I found this solution, but it's kinda strange and I feel there is some easy way to do it. Here is the way that I found
...
0
votes
0
answers
22
views
why can't add Specialization template in this case [duplicate]
when I add MYClass Specialization template , in this case, it will come out compile error, like this:
pet@iZbp1aq6c9kbbder4q405mZ:~/template_class/template_demo/2part/2_7$ g++ main.cpp test.cpp
/usr/...
1
vote
1
answer
279
views
Why is that with Visual Studio code the function declaration in header file not required?
I am using MSVC. Earlier I used Code Blocks where to share functions across files one need to put the declaration of that shared function in a header file. But with MSVC we don't need to do that, why? ...
0
votes
0
answers
26
views
global variable definition in C header file [duplicate]
I have a question about global variable in header file.
I learned that when using a preprocessor, the contents of the header are imported into the cpp file.
I think that when I write the code as below,...
1
vote
1
answer
223
views
"Unresolved external symbol" for global variables
I created a global file (Globals.h) to hold my global renderer (gRenderer) and my global window (gWindow). I declared them as extern as they'll be defined inside initWindow() & initRenderer() ...
0
votes
0
answers
55
views
How to use SetProcessMitigationPolicy with C#
I need to implement the following C++ code into C#.
PROCESS_MITIGATION_BINARY_SIGNATURE_POLICY signaturePolicy = { };
signaturePolicy.MicrosoftSignedOnly = true;
SetProcessMitigationPolicy(...
0
votes
1
answer
92
views
Function pointer to assembly label
What is wrong in these statements when trying to call a label _exit in assembly file from a function in C (in another file)? Instead of expected behavior I get the 1st instruction of _exit treated as ...
1
vote
1
answer
94
views
Why does extern template instantiation not work on move-only types?
The following code is ok:
#include <memory>
#include <vector>
extern template class std::vector<int>;
template class std::vector<int>; // ok on copyable types
int main()
{
...
0
votes
1
answer
99
views
Declaring an object as extern
I am trying to declare an object as extern because I want a thread to be able to access and update it from a different file. But I get the following error message when I try to compile my code:
In ...
0
votes
0
answers
17
views
C++ unresolved external symbol reference? [duplicate]
I have a simple Issue with my code, but I am somehow not able to solve it.
I am using the code from an old project of mine and wanted to use that code in one of my newer projects.
So I literally ...
1
vote
0
answers
51
views
Global variable and extern [duplicate]
I have this three files
header.h
extern int global_var;
header.cpp
#include "header.h"
int global_var=50;
main.cpp
#include<iostream>
#include "header.h"
using namespace ...
-2
votes
3
answers
94
views
Is it possible to use a static variable declared in another C++ library
I intend to use a library with a declaration of a variable in one of its function
/// in library A
function fun(){
static int iwanttouse = 1;
/// operation on iwanttouse
}
How can i use it ...
1
vote
1
answer
91
views
How to create an object in C++ that can be referenced globally from C code?
I have a large program in C that I'd like to use certain C++ objects with such as maps.
I followed this post on how to call C++ from C and my two C++ look like this.
///map.cc
#include "map.h&...
-1
votes
1
answer
96
views
Difficulty understanding the expression (*(&x->y))
I have the following file structure. I am aware that a pointer needs allocated memory. File A is generated by DaVinci. The main is written by me.
// File A
typedef struct {
int v1;
}s1;
struct s2{...
0
votes
2
answers
54
views
At what point during compilation or linking of C code are extern variables implicitly defined?
If I have a project with the following 3 files in the same directory:
mylib.h:
int some_global;
void set_some_global(int value);
mylib.c:
#include "mylib.h"
void set_some_global(int value)
{...
0
votes
1
answer
64
views
Using extern with multidimentional arrays in C
I have a bunch of multidimensional arrays that are allocated in local functions in different source files, but I want to make them global. I was thinking of using extern and according to this question,...
-1
votes
1
answer
53
views
How to write in a console application from another
I search for a solution how to write into an external console application from another. I look for a C# or C++ solution.
For short I want to change the color and clear the console from an already ...
0
votes
0
answers
21
views
How to use EXTERN in MASM? [duplicate]
These are my two programs:
atoi.asm
.model small
.data
ten dw 000ah
.code
atoi PROC
mov si, 2[bp]
xor cx, cx
mov cl, [si]
xor bx, bx
atoiloop1:
inc si
;;more code
;;
...
1
vote
1
answer
66
views
Make extern variable can't be accessed in specific files
So I have:
foo.h
#ifndef FOO_H
#define FOO_H
extern int bar;
void change_bar_value(const int& value);
#endif
foo.cpp
#include "foo.h"
int bar = 10;
void change_bar_value(const int&...
2
votes
1
answer
66
views
Is it valid to use extern in a local scope to unshadow a global variable?
Is this extern declaration in a nested local scope a valid and defined way to bring the global a back into the scope?
int a = 1; // may be in another file
void main() {
int a = 2; // hides the ...
-2
votes
1
answer
55
views
Non-Static Extern variable
I am initializing an extern variable in a herder file and then use it in (.c) file but when i compile my code i get an warning that says: no previous extern declaration for non-static variable.
Here ...
-1
votes
3
answers
267
views
I am getting an error of redefinition while using extern header file
I am getting an error of redefinition while using extern, but I was also told, that extern variable should be used like this, why I am getting this error and how should I use extern in this case so it ...