#EXTERN ?

4 messages · Page 1 of 1 (latest)

graceful cloak
#

guys i want to declare a constant variable : const char var[3][20] in a C header file as a prototype so should it be decalred like this const char var[3][20] or like this extern const char var[3][20] , in purpose of using it in multiple files

idle narwhalBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

tender frost
#

extern.
Without it, every c file that includes the header will have their own definition of var, causing a conflict.
Extern basically tells any file that includes it "there exists a variable call var somewhere else, use that"

#

tl;dr
extern int x; in the header.
int x = /*something*/; in ONE of your source files