Implementation of stddef.h

Per subject, implementation of stddef.h.

This implementation is correct per C99, but glibc does some funny
stuff including certain headers, so I'm not sure if this is completely
correct.

-Eli

stddef.txt (1.75 KB)

Should I take the fact that there have been no comments as meaning the
patch is bad, the patch is okay, or just that nobody with the
appropriate expertise had the time to take a look at it?

-Eli

Eli Friedman wrote:-

Should I take the fact that there have been no comments as meaning the
patch is bad, the patch is okay, or just that nobody with the
appropriate expertise had the time to take a look at it?

My only concern would be that for

  typedef __typeof__(((int*)0)-((int*)0)) ptrdiff_t;

I don't think subtracting NULL pointers is well-defined. That doesn't
matter as long as clang doesn't complain about it and does what you
expect though.

Neil.

Eli Friedman wrote:-

Should I take the fact that there have been no comments as meaning the
patch is bad, the patch is okay, or just that nobody with the
appropriate expertise had the time to take a look at it?

One more thing - since these macros use __typeof__, are we ever
going to diagnose that as an extension? If we do that might cause
a problem for user code, unless our diagnostic handlers can weasel
through the macro expansion level(s) and figure out it was actually
defined in a system header.

Neil.

AFAIK, we already suppress warnings in system headers. And, at least
for the moment, clang's implementation of -pedantic follows gcc's
version in that we don't warn about the use of anything prefixed with
double-underscore. (Since it's reserved by the standard, it's not a
constraint violation to use it, so we're conforming even if we don't
warn.)

-Eli

clang doesn't complain about it, and appears to work properly. On a
side note, the C++ standard actually explicitly defines that
((int*)0)-((int*)0) is valid compares equal to 0.

-Eli

I looked at it, seemed reasonable...

Right. Another option for similar things is the __extension__ unary expression, which turns off extension warnings for its subexpression.

-Chris