On Tue, 2013-12-03 at 16:03 +0100, Michal Židek wrote:
On 12/03/2013 02:34 PM, Simo Sorce wrote:
> On Tue, 2013-12-03 at 13:28 +0100, Michal Židek wrote:
>> On 12/03/2013 10:57 AM, Lukas Slebodnik wrote:
>
>>> I thik we can change while loop with som expresion.
>>> pad = i % sizeof(char *)
>>> pad = (pad != 0) ? sizeof(char *) - pad : 0;
>>>
>>
>> Ok, I added this change to the patch. I did not want to change the code
>> much with these patches, the purpose was to just fix the alignment
>> issues. But this is very small change and additional patch would just
>> change the same lines. So I think it is ok to include.
>>
>>> or something nicer :-) (maybe macro?)
>>
>> I do not think that obfuscation with a macro is appropriate here.
>
> Actually the code is pretty hard to read and a macro would avoid
> duplication and make it clear what the purpose is:
>
> Something like:
>
> #define PTR_SIZE sizeof(char *)
> #define ALIGN_PTR_PAD(base, padding) \
> padding = (PTR_SIZE - (base % PTR_SIZE)) % PTR_SIZE)
>
> Then in the code just call:
>
> ALIGN_PTR_PAD(i, pad)
I tend to dislike macros, but maybe we will need similar pattern on
other places in the future as well, so putting this into macro may not
be as bad idea as I originally though.
However I would propose a different macro, that would be used like this:
pad = CALCULATE_PAD(i, char *);
Maybe PADDING_SIZE() then.
Simo.
--
Simo Sorce * Red Hat, Inc * New York