• 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: OSAtomic built-in operations
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: OSAtomic built-in operations


  • Subject: Re: OSAtomic built-in operations
  • From: Stefan Werner <email@hidden>
  • Date: Sun, 06 May 2012 22:19:15 -0700

On 06.05.2012, at 21:29, Rick Mann wrote:

> I've seen this technique in other places. Why is that better than just casting pointer types? Like this:
>
> int32_t		s;
> uint32_t	u;
>
> u = *(uint32_t*) &s;

Your code has two variables and make it the programmer's job to keep them in sync. When using a union, you have two names for the same memory address. Also, the union approach is type safe where a C-style pointer cast will allow you to cast anything to a uint32_t* without the compiler warning you about it.

-Stefan
_______________________________________________

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: 
 >OSAtomic built-in operations (From: Andreas Grosam <email@hidden>)
 >Re: OSAtomic built-in operations (From: Stefan Werner <email@hidden>)
 >Re: OSAtomic built-in operations (From: Rick Mann <email@hidden>)

  • Prev by Date: Re: OSAtomic built-in operations
  • Next by Date: Problem parsing file in 64 bit build.
  • Previous by thread: Re: OSAtomic built-in operations
  • Next by thread: Problem parsing file in 64 bit build.
  • Index(es):
    • Date
    • Thread