r/arduino • u/BobsYourUncle_8192 Prolific Helper • 19d ago
Solved! I've forgotten how access variable in different .cpp
I have the following definition in one .cpp file :
static char cfgv_var_weather_icon[10] = "";
How do I set it from another .cpp file? BTW, the code was generated by LCD Wizard, not me.
All I get is red, mysterious compiler errors.
0
Upvotes
9
u/gm310509 400K , 500K , 600K , 640K , 750K 19d ago
In the other C file you use the extern modifier:
Also, you need to remove the static keyword, that will make it private.
And, if it is declared inside the body of a function you need to move it outside the function
1
u/madsci 18d ago
staticmeans the variable is specifically not to be visible to other modules. Before you change that and start accessing it from somewhere else, you should look into why that variable is static. Usually that means "this variable is for internal use only - don't touch".If this is part of a configuration and you want to move the configuration somewhere else then you can change
statictoexternand the declare it in your own configuration file.-2
u/Ok_Spare_7473 18d ago
Why don't you ask GPT about this?
Just use inline (c++) construction or extern (C-lang).