• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: copying structs - PPC/Intel different results
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: copying structs - PPC/Intel different results


  • Subject: Re: copying structs - PPC/Intel different results
  • From: Eric Albert <email@hidden>
  • Date: Wed, 28 Jun 2006 09:53:52 -0700

On Jun 28, 2006, at 9:37 AM, James Milne wrote:

On 28 Jun 2006, at 17:32, Eric Albert wrote:

On Jun 28, 2006, at 5:14 AM, Marc Poirier wrote:

Given this example:

struct Thingy {
	int a;
	int b;
	int c;
};
const Thingy kFirstThingy = { 1, 2, 3 };
const Thingy kSecondThingy = kFirstThingy;

When compiling with GCC 4.0.1 for PPC code, the three values of kSecondThingy are 1, 2, 3. But when compiling with GCC 4.0.1 for Intel code, the three values of kSecondThingy are 0, 0, 0.

I'm unsure, is one of these a bug? If so, which? I would tend to think the Intel results are wrong, though maybe I'm doing something I shouldn't be doing, I'm not sure...

Can you show a complete example?

Erics-MacBook-Pro:~> cat test.c
#include <stdio.h>

struct Thingy {
        int a;
        int b;
        int c;
};

int main(void) {
const struct Thingy kFirstThingy = { 1, 2, 3 };
const struct Thingy kSecondThingy = kFirstThingy;
printf("First a, b, c: %d, %d, %d\n", kFirstThingy.a, kFirstThingy.b, kFirstThingy.c);
printf("Second a, b, c: %d, %d, %d\n", kSecondThingy.a, kSecondThingy.b, kSecondThingy.c);
return 0;
}
Erics-MacBook-Pro:~> gcc -Wall -g -o test test.c
Erics-MacBook-Pro:~> ./test
First a, b, c: 1, 2, 3
Second a, b, c: 1, 2, 3
Erics-MacBook-Pro:~>

Try moving the constants out of the function and into the global scope.


It might be an order of initialisation issue.

I'm pretty sure order of initialization within the same module is defined to be the order things are in the code, so I don't think this can be wrong. As for global scope, I have to switch to C++ for that but I still get the same results:


Erics-MacBook-Pro:~> cat test.cpp
#include <stdio.h>

struct Thingy {
        int a;
        int b;
        int c;
};

const struct Thingy kFirstThingy = { 1, 2, 3 };
const struct Thingy kSecondThingy = kFirstThingy;

int main(void) {
printf("First a, b, c: %d, %d, %d\n", kFirstThingy.a, kFirstThingy.b, kFirstThingy.c);
printf("Second a, b, c: %d, %d, %d\n", kSecondThingy.a, kSecondThingy.b, kSecondThingy.c);
return 0;
}
Erics-MacBook-Pro:~> g++ -Wall -g -o test test.cpp
Erics-MacBook-Pro:~> ./test
First a, b, c: 1, 2, 3
Second a, b, c: 1, 2, 3
Erics-MacBook-Pro:~>


-Eric

_______________________________________________
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


References: 
 >copying structs - PPC/Intel different results (From: Marc Poirier <email@hidden>)
 >Re: copying structs - PPC/Intel different results (From: Eric Albert <email@hidden>)
 >Re: copying structs - PPC/Intel different results (From: James Milne <email@hidden>)

  • Prev by Date: Re: can I catch an EXC_BAD_ACCESS?
  • Next by Date: Re: copying structs - PPC/Intel different results
  • Previous by thread: Re: copying structs - PPC/Intel different results
  • Next by thread: Re: copying structs - PPC/Intel different results
  • Index(es):
    • Date
    • Thread