Why Static Const Almost Always Trumps Const
-
A search for actionable information about the distinction between
const
andstatic const
led me to [c - Are const Local Variables Implicitly static? - CS50 Stack Exchange](https://cs50.stackexchange.com/questions/2719/are-const-local-variables-implicitly-static/29418#29418). Finding the answer wanting, I changed the function that prompted me to raise the question in the first place. Examining the disassembly reminded me of a discovery that I made so long ago that I had forgotten the details that led me to almost always pairstatic
andconst
when I define arrays of constants, such as lookup tables and the like. Details are in the 3rd answer shown in the Stack Overflow topic.David A. Gray Delivering Solutions for the Ages, One Problem at a Time Interpreting the Fundamental Principle of Tabular Reporting
-
A search for actionable information about the distinction between
const
andstatic const
led me to [c - Are const Local Variables Implicitly static? - CS50 Stack Exchange](https://cs50.stackexchange.com/questions/2719/are-const-local-variables-implicitly-static/29418#29418). Finding the answer wanting, I changed the function that prompted me to raise the question in the first place. Examining the disassembly reminded me of a discovery that I made so long ago that I had forgotten the details that led me to almost always pairstatic
andconst
when I define arrays of constants, such as lookup tables and the like. Details are in the 3rd answer shown in the Stack Overflow topic.David A. Gray Delivering Solutions for the Ages, One Problem at a Time Interpreting the Fundamental Principle of Tabular Reporting
Nice one.
cheers Chris Maunder
-
Nice one.
cheers Chris Maunder
Thank you, Sir!
David A. Gray Delivering Solutions for the Ages, One Problem at a Time Interpreting the Fundamental Principle of Tabular Reporting
-
A search for actionable information about the distinction between
const
andstatic const
led me to [c - Are const Local Variables Implicitly static? - CS50 Stack Exchange](https://cs50.stackexchange.com/questions/2719/are-const-local-variables-implicitly-static/29418#29418). Finding the answer wanting, I changed the function that prompted me to raise the question in the first place. Examining the disassembly reminded me of a discovery that I made so long ago that I had forgotten the details that led me to almost always pairstatic
andconst
when I define arrays of constants, such as lookup tables and the like. Details are in the 3rd answer shown in the Stack Overflow topic.David A. Gray Delivering Solutions for the Ages, One Problem at a Time Interpreting the Fundamental Principle of Tabular Reporting
At first I thought this might be a compiler quirk, so I ran a couple of trivial examples through
gcc -s
. That does substantially the same, so I'm guessing it's a language feature. One for the standards committee "lawyers".Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
-
At first I thought this might be a compiler quirk, so I ran a couple of trivial examples through
gcc -s
. That does substantially the same, so I'm guessing it's a language feature. One for the standards committee "lawyers".Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
Thanks much for duplicating the observation with the other popular C compiler. As I said, I observed the same thing about a dozen years ago, but I had forgotten the details. Anyway, so far as I know, the same holds whether your code is straight ANSI C or ANSI C++. The test case that I cited in the Stack Overflow article is straight ANSI C.
David A. Gray Delivering Solutions for the Ages, One Problem at a Time Interpreting the Fundamental Principle of Tabular Reporting