Linked Questions

243 votes
3 answers
152k views

At the 2016 Oulu ISO C++ Standards meeting, a proposal called Inline Variables was voted into C++17 by the standards committee. In layman's terms, what are inline variables, how do they work and what ...
jotik's user avatar
  • 18.1k
100 votes
7 answers
25k views

See subject. What were they thinking? UPDATE: Changed from "static" to "internal linkage" to save confusion. To give an example... Putting the following in a file: const int var_a = 1; int var_b = ...
Johan Kotlinski's user avatar
99 votes
7 answers
39k views

Is it possible to declare a variable extern constexpr and define it in another file? I tried it but the compiler gives error: Declaration of constexpr variable 'i' is not a definition in .h: ...
coldbrew's user avatar
  • 1,003
68 votes
4 answers
47k views

I have a namespace foo which contains an integer bar, declared so... foo.h: namespace foo { int bar; } Now if I include foo.h in only one file, this works just fine. But a problem arises when I ...
Michael Francis's user avatar
45 votes
4 answers
58k views

I want to share certain C string constants across multiple c files. The constants span multiple lines for readability: const char *QUERY = "SELECT a,b,c " "FROM table..."; Doing ...
Manish's user avatar
  • 2,115
22 votes
3 answers
16k views

// MyClass.h namespace MyNamespace { static const double GasConstant = 1.987; class MyClass { // constructors, methods, etc. }; } I previously had GasConstant declared within the ...
mindless.panda's user avatar
6 votes
5 answers
3k views

I have the following three files in my code (with most of the code removed. This is just to isolate the issue). global.h: //global.h #ifndef GLOBAL_H #define GLOBAL_H extern const int ARRAYSIZEX; ...
boxcartenant's user avatar
0 votes
2 answers
8k views

I know there is another post here that is how to clear a single bit, but how about a whole byte? For example, if I had 00000000 00000000 00101100 11000100 and I wanted to clear the second chunk so it ...
PhantomProgramer's user avatar
2 votes
1 answer
2k views

We have a piece of C-code in our system which contains a few arrays like this with global access: source.h extern const int magic[5]; source.c: const int magic[] = { 1, 2, 3, 4, 5}; Somebody ...
Tom Tanner's user avatar
  • 9,380
1 vote
2 answers
585 views

I try to use a global variable as elements for an array. The problem is that the compiler want to know the integer constant value while declaring an array. I thought that my global variable is ...
Module_art's user avatar
  • 1,069
2 votes
1 answer
518 views

I am creating an component, generalization of a template. For creation must be used string identifier. I am replacing: #define MYCOMPONENT_CONSTANT_IDENTIFIER "ID value" with namespace ...
urkon's user avatar
  • 263
1 vote
3 answers
351 views

If I have a string variable in a header file which will be used across different files and translation units, should I store it in a constexpr const char* or const std::string? Here is an example: // ...
Komgcn's user avatar
  • 355