0

This question related to accepted answer to this question. The answer states that you can add the version as a char somewhere in the library code.

char* library_version = { "Version: 1.3.6" };

If I was following the approach for an executable, I would just place this somewhere in the beginning of main. Where should it be placed in a library to be sure it will be executed?

Community
  • 1
  • 1
TheMeaningfulEngineer
  • 15,679
  • 27
  • 85
  • 143
  • It's a symbol that holds a string. It's not a function. You don't execute a string. – user3528438 May 26 '15 at 14:16
  • 1
    Just note that if you do this, the `library_version` should be a rather unique name as to not clash with other libraries. e.g. `libfoo_version` – nos May 26 '15 at 14:20

1 Answers1

1

In the same place than other global variables declaration.
Please notice this is a variable declaration, this is not an instruction, it will never be executed. What can be executed is a function returning this variable or comparing it with an other

Quicky
  • 403
  • 1
  • 4
  • 10
  • So it would be in some `global-include.h` header file? – TheMeaningfulEngineer May 26 '15 at 14:28
  • Yes by example, or it can be in an other include file of the lib – Quicky May 26 '15 at 14:29
  • No, that's not a good idea, with out `static` you'll have multiple definition error, and with `static` you duplicate the string each time you include it somewhere. Just put it in a source file, any source file that have access to global name space. – user3528438 May 26 '15 at 14:32
  • @user3528438: Certainly it should be in a source file... but why are you singling out "some" files that would not have access to the global namespace? All files can access it. – Matthieu M. May 26 '15 at 14:36