• 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
Odd GCC Behavior
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Odd GCC Behavior


  • Subject: Odd GCC Behavior
  • From: "J. Aaron Pendergrass" <email@hidden>
  • Date: Mon, 30 Jun 2008 09:21:02 -0400

Hello list,
I just ran into what seems to be fairly peculiar behavior of Apple's GCC (v4.0.1 PPC) that seemed worth
pointing out. It is hard to say if it is really a bug since the C spec is fairly non-deterministic,
but it is peculiar.


Here's some sample code that demonstrates the behavior:

{
	long stack[4] = {1,2,3,4};
	long *sp  = test + 4;   /* top of stack is at (sp - 1) */

	/* add the top of stack to the next element and pop */
	*(sp - 2) += *(--sp);
}

One might expect this to result in a stack like:

{1, 2, 7, 4}

This is the behavior of GNU GCC (v 4.2.3 on Ubuntu x86-32) and Apple GCC (v4.0.1)
on Intel. Another reasonable guess might be that the prefix-decrement would
be evaluated before the lhs is resolved to a value which should result in:


{1, 6, 3, 4}

But in fact it results in:
{1, 7, 3, 4}

This just seems bizarre to me.
The most bizarre part in my mind is that one might think the program
above should be identical to:

{
	long stack[4] = {1,2,3,4}
	int sp = 4;
	stack[sp-2] += stack[--sp];
}

but this snippet actually results in {1,2,7,4}.

Again, I'm not sure that this is really a bug since the C spec is annoyingly vague about exactly
when prefix increment/decrement is supposed to happen. But it seems like it should at least be
consistent between the two cases.


Does anyone have insight into this?

Thanks,
-Aaron
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Odd GCC Behavior
      • From: Jim Jagielski <email@hidden>
    • Re: Odd GCC Behavior
      • From: Andrew Pinski <email@hidden>
    • Re: Odd GCC Behavior
      • From: Andrew Pinski <email@hidden>
  • Prev by Date: Building Python SDK from Darwin sources
  • Next by Date: Re: Odd GCC Behavior
  • Previous by thread: Re: Building Python SDK from Darwin sources
  • Next by thread: Re: Odd GCC Behavior
  • Index(es):
    • Date
    • Thread