local static variables' default initialization

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • auspicious

    #1

    local static variables' default initialization

    Hi,

    I would like to know what does the standard say about initialization
    of local static variable's default initialization.

    void f(int a)
    {
    static int b;
    b+=a;
    }

    Shall 'b' be initialized to zero by default in this case or shall it
    produce an error?
  • Sam

    #2
    Re: local static variables' default initialization

    auspicious writes:
    Hi,
    >
    I would like to know what does the standard say about initialization
    of local static variable's default initialization.
    >
    void f(int a)
    {
    static int b;
    b+=a;
    }
    >
    Shall 'b' be initialized to zero by default in this case or shall it
    produce an error?
    It will be zero.


    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.4.9 (GNU/Linux)

    iEYEABECAAYFAkj cDL8ACgkQx9p3GY HlUOIEDwCeIB2SF Qgsx+hvFsmBGhEZ LrKI
    WUgAn3F0zGjdz2s EisQqslo5a9vNbS/H
    =3Sfp
    -----END PGP SIGNATURE-----

    Comment

    • blargg

      #3
      Re: local static variables' default initialization

      In article
      <965527ed-e0c5-493d-83fc-f8efde6a3df0@73 g2000hsx.google groups.com>,
      auspicious <auspicious.me@ gmail.comwrote:
      I would like to know what does the standard say about initialization
      of local static variable's default initialization.
      >
      void f(int a)
      {
      static int b;
      b+=a;
      }
      >
      Shall 'b' be initialized to zero by default in this case or shall it
      produce an error?
      Zero. See 3.7.1 and 6.7 paragraph 4.

      Comment

      Working...