public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/47702] New: feature request: sentinel_value
@ 2011-02-11 17:12 ericb at gcc dot gnu.org
  0 siblings, 0 replies; only message in thread
From: ericb at gcc dot gnu.org @ 2011-02-11 17:12 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2011-02-11 17:10 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-02-11 17:12 [Bug c/47702] New: feature request: sentinel_value ericb at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).