Re: #define bug in gcc for delta builds?
Re: #define bug in gcc for delta builds?
- Subject: Re: #define bug in gcc for delta builds?
- From: Steve Checkoway <email@hidden>
- Date: Wed, 4 Feb 2009 03:36:59 -0800
On Feb 4, 2009, at 3:28 AM, Matt Gough wrote:
if you declare globals this way, aren't they unique to each
compilation unit?
i.e if bar.cpp and roo.cpp both #include foo.h then they both refer
to globals called A but they are in different locations (and hence
not the same A)
Nope, they're the same A and you get an error:
[dualg5:~/temp] steve$ cat foo.h
int A = 1;
[dualg5:~/temp] steve$ cat bar1.cpp
#include "foo.h"
int getA() { return A; }
[dualg5:~/temp] steve$ cat bar2.cpp
#include <cstdio>
#include "foo.h"
int getA();
int main()
{
A = 5;
printf( "%d %d\n", A, getA() );
return 0;
}
No you might expect it to print "5 1" but actually it's an error.
[dualg5:~/temp] steve$ g++ bar1.cpp bar2.cpp
ld: duplicate symbol _A in /var/folders/M1/M1WmohhpE7CR4qhrVy2-0U++
+yc/-Tmp-//ccQURsZQ.o and /var/folders/M1/M1WmohhpE7CR4qhrVy2-0U+++yc/-
Tmp-//ccUxyo7j.o
collect2: ld returned 1 exit status
--
Steve Checkoway
"Anyone who says that the solution is to educate the users
hasn't ever met an actual user." -- Bruce Schneier
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden