[PATCH 2/3] sys/cdefs.h: export __attribute_alloc_size__

Roland McGrath roland@hack.frob.com
Wed Jan 23 23:09:00 GMT 2013


__VA_ARGS__ is C99 and so gets warnings under -std=c89 -pedantic.
We should avoid it rather than relying on the system-header exception.
Here it's trivial just to do:

	# define __attribute_alloc_size__(params) \
	     __attribute__ ((__alloc_size__ params))

	extern void *blah (size_t, size_t) __attribute_alloc_size__ ((1, 2));

> 	* include/sys/cdefs.h (__attribute_alloc_size): Delete.

Say, "Macro removed."

> 	* misc/sys/cdefs.h (__attribute_alloc_size__): Define.

Say, "New macro."

> +/* Tell gcc where to find the size param for malloc funcs.  */

Use full English words, correct capitalization for things like proper nouns
(i.e. "GCC"), and a fully coherent explanation.  Here I'd write:

/* Tell the compiler which arguments to an allocation function
   indicate the size of the allocation.  */

> +# define __attribute_alloc_size__(...) \
> +     __attribute__ ((__alloc_size__ (__VA_ARGS__)))

The norm here is to indent the continuation line just two spaces.
A reasonable alternative is two spaces from "define".  Three spaces
from "define" is not compatible with our style.

> +# define __attribute_alloc_size__(...) /* Ignore */

It's preferable to use a tab (or multiple tabs, if there is something
nearby to line up with) between the lhs and rhs of a macro definition.
The comment is not really necessary at all here, but if it's there
it should read "/* Ignore.  */".  

The contrary style examples in the file are errors to be fixed,
not models to be followed.

The change is OK with those issues fixed.


Thanks,
Roland



More information about the Libc-alpha mailing list