Boost logo

Boost :

From: Yitzhak Sapir (ysapir_at_[hidden])
Date: 2002-01-31 09:35:09


header:
namespace { struct a { int x; }; static a z; }
int sum1(int x, int y);
int sum2(int x, int y);

file 1:
#include "stdafx.h"

int sum2(int x, int y)
{
        return x + y + z.x;
}

file 2:
#include "stdafx.h"

int sum1(int x, int y)
{
        return x + y + z.x;
}

int main(int argc, char* argv[])
{
        z.x = 4;
        int b1 = sum1(2 ,3);
        z.x = 5;
        int b2 = sum2(4, 3);
        return 0;
}

compiles fine with precomp headers, but doesn't with precomp headers and
without the static.

-----Original Message-----
From: Fernando Cacciola [mailto:fcacciola_at_[hidden]]
Sent: Thursday, January 31, 2002 4:26 PM
To: boost_at_[hidden]
Subject: RE: [boost] boost bind/functional/reference wrapper/mem_fn

----- Original Message -----
From: Yitzhak Sapir <ysapir_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Thursday, January 31, 2002 11:22 AM
Subject: RE: [boost] boost bind/functional/reference wrapper/mem_fn

> My experiment had a header which declared an int variable in an
unnamed
> namespace. Then it had two source files which use this variable in
> functions (which sum this variable with their parameters), and the
> main() in one source file called both functions. This produced a
> problem when compiled with precompiled headers. When I changed the
int
> to static int (still in an unnamed namespace), it didn't have
problems.
> When run it seems to keep a different copy of the int for each source
> file.
>
I see.
Now try declaring a static object of class type, not of built-in type:

struct A {} ;
static /*or const*/ A a ;

Alternatively, try with 'double' instead of 'int'.

I think that this won't precompile.

Fernando Cacciola
Sierra s.r.l.
fcacciola_at_[hidden]
www.gosierra.com

Info: http://www.boost.org Send unsubscribe requests to:
<mailto:boost-unsubscribe_at_[hidden]>

Your use of Yahoo! Groups is subject to
http://docs.yahoo.com/info/terms/


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk