0

I have a code, that is split into multiple files, and which has to use a lot of constant strings(hundreds), and many of them have to be accessed from functions located in several files, what is the most convenient way to do this?

2 Answers 2

3

You can make a header called e.g., global.h and put your constants on it and include where the constants is needed(in fact,you will include for context,because you need to use include guards for avoid redefinition error)

2
  • Yes, I figured it out, I put definitions in conststr.c, and declarations using extern into conststr.h, seems to be working so far... thanks.
    – wirm
    Jan 7, 2013 at 13:33
  • 1
    To avoid linker issues, it is best to never define any variables in header fines. In the header file, declare the variables as extern const int blah; and in a corresponding C file, define the variables as const int blah;. And use header guards as well.
    – Lundin
    Jan 7, 2013 at 14:50
0

You can use array of pointers where each pointer points to one string. You can pass the string array where ever you want to other functions, but only thing is make it as const so that no one will change that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.