RFC: Aligning data in buffers with a macro?

Carlos O'Donell carlos@systemhalted.org
Sun Apr 1 19:13:00 GMT 2012


On Sun, Apr 1, 2012 at 12:30 PM, Marek Polacek <polacek@redhat.com> wrote:
>>  628 # elif _STACK_GROWS_UP
>>  629           char *guard = (char *) ALIGN_DOWN((uintptr_t) pd -
>> guardsize, pagesize_m1);
>>  630 #endif
>
> To be honest, that doesn't make much difference to me.  The second
> variant is not shorter nor more readable I suspect.  Also I have
> a qualm about these changes--they might be quite error-prone.

It is my opinion that using a macro with a clear purpose makes the
code more understandable e.g. Are you aligning up, or down, and to
what alignment?

We could shorten it to _ALIGND(...) or _ALIGNU().

I do *not* propose we go through and fixup everything.

I do propose using the alignment macros when writing new code or
fixing existing code to make the intent of the action clear.

I would rather learn to read through _ALIGND and _ALIGNU than have to
do the masking operations mentally to figure out what the author
intended.

Cheers,
Carlos.



More information about the Libc-alpha mailing list