• 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: Dave Keck <email@hidden>
  • Date: Mon, 07 May 2012 01:00:14 -0400

>>    union {
>>        int32_t s;
>>        uint32_t u;
>>    } atomicvar;
>>    atomicvar.u = 0;
>>    OSAtomicCompareAndSwap32(0, 1, &atomicvar.s);
>>    OSAtomicOr32Orig(0, &atomicvar.u);
>
> 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;

Indeed -- and my understanding is C only guarantees that the most
recently-assigned member of a union to be valid. So if the OP is
worried about correctness, it would seem the union approach doesn't
help.

_______________________________________________

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: Re: OSAtomic built-in operations
  • Previous by thread: Re: OSAtomic built-in operations
  • Next by thread: Re: OSAtomic built-in operations
  • Index(es):
    • Date
    • Thread