[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c++

local static variables' default initialization

auspicious

9/25/2008 10:03:00 PM

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?
2 Answers

Sam

9/25/2008 10:12:00 PM

0

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.

blargg.h4g

9/25/2008 10:19:00 PM

0

In article
<965527ed-e0c5-493d-83fc-f8efde6a3df0@73g2000hsx.googlegroups.com>,
auspicious <auspicious.me@gmail.com> wrote:
> 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.