• 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: To get machine type (ppc, intel)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: To get machine type (ppc, intel)


  • Subject: Re: To get machine type (ppc, intel)
  • From: "Sherm Pendley" <email@hidden>
  • Date: Wed, 19 Mar 2008 13:43:53 -0400

On Wed, Mar 19, 2008 at 10:14 AM, Nick Rogers <email@hidden> wrote:

> Hi,
> In my app I'm reading raw bytes from the file.
> So to get a integer's correct value, I'll need to swap bytes
> according to the machine (big or little-endian type), I guess.
>
> Is there a way so that I can know, if its a intel or ppc machine,
> that my app is running on?


It would be better to write code that doesn't need to know that - it'll be
portable to any other hardware Apple uses in the future. (For example, I
have no idea if the iPhone or iPod are little or big endian.)

There are a number of functions in Foundation that allow you to write such
code. For instance, NSSwapBigShortToHost() will take a big endian short, and
return a short that's in the correct format for whatever machine the code
happens to be running on; if it's called on a big endian system, it's a
no-op. There are many such functions - have a look in the "Byte Ordering"
section here:

    <
http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Functions/Reference/reference.html
>

There are also Core Endian functions:

    <
http://developer.apple.com/documentation/Carbon/Reference/CoreEndianReference/Reference/reference.html
>

sherm--
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >To get machine type (ppc, intel) (From: Nick Rogers <email@hidden>)

  • Prev by Date: Re: Network communication with NSFileHandle & NSSocketPort
  • Next by Date: Intercepting retain/release of object
  • Previous by thread: Re: To get machine type (ppc, intel)
  • Next by thread: Kentucky Meetup
  • Index(es):
    • Date
    • Thread