This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/47702] New: feature request: sentinel_value


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]).


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]