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)
If you really dislike the macro and want to put in direct code at least
do this:
/* align to char * pointers sizes */
pad = (sizeof(char *) - (i % sizeof(char *)
pad %= sizeof(char *)
HTH,
Simo.
--
Simo Sorce * Red Hat, Inc * New York