Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. Why Static Const Almost Always Trumps Const

Why Static Const Almost Always Trumps Const

Scheduled Pinned Locked Moved The Weird and The Wonderful
questioncomdata-structureshelp
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    David A Gray
    wrote on last edited by
    #1

    A search for actionable information about the distinction between const and static 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 pair static and const 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

    C P 2 Replies Last reply
    0
    • D David A Gray

      A search for actionable information about the distinction between const and static 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 pair static and const 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

      C Offline
      C Offline
      Chris Maunder
      wrote on last edited by
      #2

      Nice one.

      cheers Chris Maunder

      D 1 Reply Last reply
      0
      • C Chris Maunder

        Nice one.

        cheers Chris Maunder

        D Offline
        D Offline
        David A Gray
        wrote on last edited by
        #3

        Thank you, Sir!

        David A. Gray Delivering Solutions for the Ages, One Problem at a Time Interpreting the Fundamental Principle of Tabular Reporting

        1 Reply Last reply
        0
        • D David A Gray

          A search for actionable information about the distinction between const and static 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 pair static and const 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

          P Offline
          P Offline
          Peter_in_2780
          wrote on last edited by
          #4

          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

          D 1 Reply Last reply
          0
          • P Peter_in_2780

            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

            D Offline
            D Offline
            David A Gray
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups