POSIX 2008 C Extensions and restrict Keyword

Joel Sherrill joel.sherrill@oarcorp.com
Tue Jul 9 13:50:00 GMT 2013


I was reviewing a standards checker report on RTEMS and noticed
that there are a couple of areas in newlib that need some attention.
I am sure there are more than this one case that fall into these
two categories of issues. But I wanted to get some general guidance
on how to proceed based on this one case -- strtok() and strtok_r().


#include <string.h>

char *strtok(char *restrict s1, const char *restrict s2);

[CX]  char *strtok_r(char *restrict s, const char *restrict sep,
        char **restrict lasts);

(1) From the notes, the restrict keyword was added for alignment
with ISO/IEC 9899:1999 which is C99.  The current sys/cdefs.h
defines __restrict which is conditionalized based on the compiler
and language version. Would it be OK to start sweeping __restrict
in per POSIX/C99?

(2) strtok_r() is part of the POSIX extensions to the C Library. But
it is wrapped only in __STRICT_ANSI__ while other methods
in string.h are wrapped in this:

!defined(__STRICT_ANSI__) || (_XOPEN_SOURCE - 0) >= 500.

Should all the methods marked CX (C Library Extensions) in the
POSIX standard be in a similar conditional? If so what should the
test be?

That should be enough to start a large chunk of work based on. :)

Joel Sherrill, Ph.D.             Director of Research & Development
joel.sherrill@OARcorp.com        On-Line Applications Research
Ask me about RTEMS: a free RTOS  Huntsville AL 35805
Support Available                (256) 722-9985

More information about the Newlib mailing list