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

Re: Odd GCC Behavior


  • Subject: Re: Odd GCC Behavior
  • From: Steve Sisak <email@hidden>
  • Date: Mon, 30 Jun 2008 13:12:51 -0400

At 12:36 PM -0400 6/30/08, J. Aaron Pendergrass wrote:
Of course there's a choice to be made.
The compiler has to do something. It chose to do something on powerpc that is
completely different from what it chooses to do on other architectures, and on other
programs which have very similar undefined usages, and which seemed somewhat
unintuitive (in the sense that if I were to define a particular behavior it would not have
been the one I observed).


I'm curious what the motivation is for this particular choice.
If you don't know the answer don't respond.

Because PPC and Intel have different instruction sets and therefor different optimizers. What the spec is saying by "undefined" is that "if a programmer writes code like this it's a bug" so there's no need for compiler writers to do anything but what's most convenient.


This is a very common interview question to test basic literacy in the in the C programming language.

If you see someone writing code like this it's a good signal not to trust other they write (and not to hire them). :-)

To be correct, you MUST write it on 2 lines:

{
	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 -= 1;
	*(sp - 2) += *sp;
}

There are still some people who think that reducing the number of lines of C somehow reduces code size.

Are you sure you aren't trying to get us to do your homework? ;-)

Cheers,

-Steve
_______________________________________________
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: "J. Aaron Pendergrass" <email@hidden>
References: 
 >Odd GCC Behavior (From: "J. Aaron Pendergrass" <email@hidden>)
 >Re: Odd GCC Behavior (From: Jim Jagielski <email@hidden>)
 >Re: Odd GCC Behavior (From: "J. Aaron Pendergrass" <email@hidden>)
 >Re: Odd GCC Behavior (From: "Clark Cox" <email@hidden>)
 >Re: Odd GCC Behavior (From: "J. Aaron Pendergrass" <email@hidden>)

  • Prev by Date: Re: Odd GCC Behavior
  • Next by Date: Re: Odd GCC Behavior
  • Previous by thread: Re: Odd GCC Behavior
  • Next by thread: Re: Odd GCC Behavior
  • Index(es):
    • Date
    • Thread