• 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: Unsigned Long Long
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Unsigned Long Long


  • Subject: Re: Unsigned Long Long
  • From: Sherm Pendley <email@hidden>
  • Date: Wed, 12 May 2004 23:00:13 -0400

On May 12, 2004, at 10:05 PM, Clark Cox wrote:

On May 12, 2004, at 21:15, Sherm Pendley wrote:

Bit-shifting is faster than division:

...but then you make a statement that is also not supported by the standard.

I didn't say it was. Nor did I state or imply that it should it be - it's an implementation detail, not part of the language definition.

Regardless, any introductory programming text or class will tell you the same thing. If you're multiplying or dividing by a power of two, bit-shifting is always faster than integer division.

long long kb = b >> 10;

It is far less clear what the actual intent here is

It's clear to anyone who's spent at least a week programming in C. But if you're concerned about beginners being able to grok it, just use longer variable names, and add a comment:

// Divide by 1024 to get KB - use >> for speed
long long kilobytes = bytes >> 10;

Assuming of course that GCC doesn't optimize division by a constant power of 2 into a bit-shift on its own.

That is a bad assumption to make, for something so easily testable, there is no need to assume.

What are you suggesting, that I benchmark the bit-shift operators and/or examine the assembly code produced by every compiler available? Is that your idea of "easily testable?" Why would I go to such absurd lengths, when there's a trivially simple alternative that's guaranteed to produce optimal code with any C compiler for any modern CPU?

sherm--
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


  • Follow-Ups:
    • Re: Unsigned Long Long
      • From: Clark Cox <email@hidden>
References: 
 >Unsigned Long Long (From: email@hidden)
 >Re: Unsigned Long Long (From: Fritz Anderson <email@hidden>)
 >Re: Unsigned Long Long (From: Sherm Pendley <email@hidden>)
 >Re: Unsigned Long Long (From: Clark Cox <email@hidden>)

  • Prev by Date: Re: umbrella frameworks and the likes
  • Next by Date: Re: Unsigned Long Long
  • Previous by thread: Re: Unsigned Long Long
  • Next by thread: Re: Unsigned Long Long
  • Index(es):
    • Date
    • Thread