I have multiple C files 1.c 2.c and 3.c and their correspondent headers 1.h 2.h 3.h. these files use the same static char* variable so I want to define this variable in one header file. Is there any solution?
like : #define nameVariable valueVariable
NB :
None of the c files include another header (i.e 1.c dont include 2.h and 3.h etc..).
All of the 3 files include a 4.h file.
All of the 3 files have the same Makefile.
const char *YourClass::SOMETHING = "something"; C++ standard, 9.4. 2/4: If a static data member is of const integral or const enumeration type, its declaration in the class definition can specify a constant-initializer which shall be an integral constant expression.
h is the header in the C standard library for the C programming language which contains macro definitions, constants and declarations of functions and types used not only for string handling but also various memory handling functions; the name is thus something of a misnomer.
In order to declare a variable with character type, you use the char keyword followed by the variable name. The following example declares three char variables. char ch; char key, flag;.
If the variable in question is a constant string that will never change, you can get away with using a #define
for this.
In 4.h:
#define MY_STATIC_STRING "my_string"
This will perform a text substitution in each source file anyplace you use MY_STATIC_STRING
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With