Re: OSAtomic built-in operations

2012-05-06 Thread Stefan Werner
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

Re: OSAtomic built-in operations

2012-05-06 Thread Dave Keck
>>    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 t

Re: OSAtomic built-in operations

2012-05-06 Thread Rick Mann
On May 6, 2012, at 17:11 , Stefan Werner wrote: > Have you tried union{} ? > >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

Re: OSAtomic built-in operations

2012-05-06 Thread Stefan Werner
On 06.05.2012, at 02:05, Andreas Grosam wrote: > I would like to use OSAtomicCompareAndSwap32 and OSAtomicOr32Orig using the > same variable. Unfortunately, the first requires a signed int, the other an > unsigned int. > > How can I get this to work? Have you tried union{} ? union {

OSAtomic built-in operations

2012-05-06 Thread Andreas Grosam
Hi All! I would like to use OSAtomicCompareAndSwap32 and OSAtomicOr32Orig using the same variable. Unfortunately, the first requires a signed int, the other an unsigned int. How can I get this to work? Example: enum { State_Canceling = 1U << 7; }; int _state; // would like to have