This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/47702] New: feature request: sentinel_value
- From: "ericb at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 11 Feb 2011 17:09:59 +0000
- Subject: [Bug c/47702] New: feature request: sentinel_value
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47702
Summary: feature request: sentinel_value
Product: gcc
Version: 4.4.5
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: ericb@gcc.gnu.org
__attribute__((sentinel)) is great for detecting a trailing NULL argument. But
what about code that wants to detect some other trailing sentinel argument?
For example:
#include <stdarg.h>
enum flags {
FLAG_A,
FLAG_B,
FLAG_C,
FLAG_LAST
};
void setFlags(int *result, ...)
{
va_list list;
int flag;
va_start(list, result);
while ((flag = va_arg(list, int)) != FLAG_LAST)
*result |= 1 << flag;
va_end(list);
}
int main (void)
{
int flags;
setFlags(flags, FLAG_A, FLAG_C, FLAG_LAST);
return flags;
}
I'd love to be able to mark that all callers of setFlags must provide a
trailing argument of FLAG_LAST as their sentinel value.
Would it be possible to introduce:
__attribute__((sentinel_value(value, [position])))
and make the current sentinel([position]) be strictly equivalent to
sentinel_value(NULL, [position]).