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

Thread: static keyword

Threaded View

  1. #1
    Join Date
    Aug 2003
    Location
    Canada
    Posts
    164

    Question static keyword

    1.

    Is there any reason / benefit to modifying a file scope variable (declared outside of any function, block, or class -- i.e. a global variable) with the static keyword? For example:

    static const int a = 123; // file scope

    rather than just:

    const int a = 123; // file scope

    It appears that the static keyword changes nothing. Is this correct?

    2.

    The following two bolded sentences appear to be contradictory:

    http://msdn2.microsoft.com/en-us/library/xfx9kcae.aspx
    "A name specified using the static keyword has internal linkage except for the static members of a class that have external linkage. That is, it is not visible outside the current translation unit."

    http://msdn2.microsoft.com/en-us/library/s1sb61xd.aspx
    "When modifying a variable or function at file scope, the static keyword specifies that the variable or function has internal linkage (its name is not visible from outside the file in which it is declared)."

    Any thoughts to clear this up? Testing shows the first is correct. And I would guess it is correct based on the thought: Exactly how could a variable not be visible outside of its own file, if this file were included into another? Is the second statement incorrect, or does it have meaning that I am unaware of?
    Last edited by JasonD; November 22nd, 2006 at 05:34 PM.

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