By: Ricardo B (ricardo.b.delete@this.xxxxx.xx), October 30, 2006 7:54 am
Room: Moderated Discussions
Gabriele Svelto (gabriele.svelto@gmail.com) on 10/30/06 wrote:
---------------------------
>>
>>For example, the following code is legit:
>>char someBuffer[BUFFER_SIZE];
>>int32_t * someField = (int*)someBuffer + 10;
>>*someField = 2;
>
>Mmm... Your code doesn't create an unaligned pointer, someBuffer will be first
>cast to an int and then 10 * sizeof(int) will be added to it so you will end up
>with an aligned int pointer albeit aliasing with a char pointer.
Indeed, I meant:
int32_t * someField = (int*)(someBuffer+10);
But to be pedantic, unless someBuffer is aligned to 4 bytes, (int*)someBuffer+n won't be aligned either.
>Gabriele
>
>PS: Sorry, this happens everytime I post on the net, I am a "he", I know that Gabriele
>sounds like a woman's name but it is not in italian :|
Trust me, I won't make that mistake again.
---------------------------
>>
>>For example, the following code is legit:
>>char someBuffer[BUFFER_SIZE];
>>int32_t * someField = (int*)someBuffer + 10;
>>*someField = 2;
>
>Mmm... Your code doesn't create an unaligned pointer, someBuffer will be first
>cast to an int and then 10 * sizeof(int) will be added to it so you will end up
>with an aligned int pointer albeit aliasing with a char pointer.
Indeed, I meant:
int32_t * someField = (int*)(someBuffer+10);
But to be pedantic, unless someBuffer is aligned to 4 bytes, (int*)someBuffer+n won't be aligned either.
>Gabriele
>
>PS: Sorry, this happens everytime I post on the net, I am a "he", I know that Gabriele
>sounds like a woman's name but it is not in italian :|
Trust me, I won't make that mistake again.