On 05/11/2012 04:49 PM, Cristian Rodríguez wrote:
El 11/05/12 16:53, David C. Rankin escribió:
Now to change it so it automatically add the NULL :)
No ! the person that wrote the example knew what was doing !
just annotate the function with __attribute__ ((sentinel)) and GCC will warn you if you are missing the final NULL.
Wow! You spend ...way... too much time with gcc :) I found it and it makes sense -- this is the first time I have stumbled across this attribute: sentinel This function attribute ensures that a parameter in a function call is an explicit NULL. The attribute is only valid on variadic functions. By default, the sentinel is located at position zero, the last parameter of the function call. If an optional integer position argument P is supplied to the attribute, the sentinel must be located at position P counting backwards from the end of the argument list. __attribute__ ((sentinel)) is equivalent to __attribute__ ((sentinel(0))) Works too! With the attribute declared, attempting to pass the parameter list without an explicit NULL provides a nice warning: char * concat (const char *str, ...) __attribute__ ((sentinel)); ~/dev/io/file> gcc -Wall -oct contest.c contest.c: In function ‘main’: contest.c:28:3: warning: missing sentinel in function call [-Wformat] Adreas, This would be a great place in the manual for 2.16 to illustrate this functionality. It may already be in the manual somewhere, but it wouldn't help to include it here since you will already be making changes to the missing declaration for 's'. The more examples of it that are spread around the manual, the less dust section 6.30 will collect :) -- David C. Rankin, J.D.,P.E. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org