Re: Need help with C syntax in examples from 'Learning Core Audio' book
Re: Need help with C syntax in examples from 'Learning Core Audio' book
- Subject: Re: Need help with C syntax in examples from 'Learning Core Audio' book
- From: David Duncan <email@hidden>
- Date: Fri, 18 May 2012 19:49:14 -0700
On May 18, 2012, at 6:54 PM, Raimondas K. wrote:
> On Wed, May 16, 2012 at 7:29 AM, Brian Lambert <email@hidden> wrote:
>> It is taking the value of error and converting it from the host’s native
>> byte order to big-endian format.
>> CFSwapInt32HostToBig(error);
>>
>> It then writes the binary value of the error in big-endian format to bytes
>> 1,2,3,4 of the 20 character error string.
>>
>> (errorString + 1) is a pointer to byte 1 of the 20 character string.
>>
>> (UInt32 *)(errorString + 1) casts this pointer to be a pointer to a UInt32.
>>
>> *(UInt32 *)(errorString + 1) dereferences this UInt32 pointer, allowing it
>> to be used as an l-value.
>
>
> I am surprised this actually works -- no byte alignment issues?
Depends on compiler and CPU architecture. I'm fairly certain this won't be an issue on any combination that Mac OS X or iOS supports today.
>
> =R.
>
>>
>> So, this allows one to assign the UInt32 value
>> of CFSwapInt32HostToBig(error) into bytes 1,2,3,4 of the 20 character error
>> string as though it was a UInt32.
>>
>> Then the code goes on to examine the bytes using isprint.
>>
>>
>> On Wed, May 16, 2012 at 4:00 AM, Ben <email@hidden>
>> wrote:
>>>
>>> I'm running through the examples in the book 'Learning Core Audio' and I
>>> came across these two lines...
>>>
>>>
>>> char errorString[20];
>>> // see if it appears to be a 4-char-code
>>> *(UInt32 *)(errorString + 1) = CFSwapInt32HostToBig(error);
>>>
>>> The second line looks pretty alien to me (rusty on C), can someone explain
>>> what is going on please? I understand what the function
>>> CFSwapInt32HostToBig() is doing, but what is going on with errorString?
>>>
>>> Thanks in advance.
>>> _______________________________________________
>>> Do not post admin requests to the list. They will be ignored.
>>> Coreaudio-api mailing list (email@hidden)
>>> Help/Unsubscribe/Update your Subscription:
>>>
>>>
>>> This email sent to email@hidden
>>
>>
>>
>> _______________________________________________
>> Do not post admin requests to the list. They will be ignored.
>> Coreaudio-api mailing list (email@hidden)
>> Help/Unsubscribe/Update your Subscription:
>>
>> This email sent to email@hidden
>>
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Coreaudio-api mailing list (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
--
Reality is what, when you stop believing in it, doesn't go away.
Failure is not an option. It is a privilege reserved for those who try.
David Duncan
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden