CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 23

Threaded View

  1. #15
    Join Date
    Feb 2009
    Location
    Portland, OR
    Posts
    1,488

    Re: allow literal string only

    Quote Originally Posted by OReubens View Post
    Hmmm I'm actually confused as to why this difference (having or not having 'static') actually matters on a const at function scope...
    static keyword on a data storage container (i.e. variable) makes compiler to place it in a different memory segment (i.e. read-only section if 'const' is used or implied) thus I gave you an example above on how to detect it. My code has to be run only in a debugger (or even your special) build. It can point lines of code where your strings are allocated dynamically that will help you change the code. In case of a big development team, you can do such checks once in a while to correct it up to your standards.

    Otherwise there's no mechanism that is built in the currently available compiler to tell the difference and all your attempts to circumvent it won't result in a better (or safer) code. I think I heard this one before...

    Oh, and const keyword simply instructs your compiler to catch any assignments done to the variable. It does nothing regarding placement in memory. It can be both a local stack/heap or a read-only memory.

    Listen, not to be a pill, but why do you need such distinction in strings? And what are your "performance issues"?
    Last edited by ahmd; July 14th, 2010 at 11:50 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured