ANSI conformance of newlib

J. Johnston jjohnstn@redhat.com
Wed Jun 25 09:54:00 GMT 2003


Jyothi wrote:
> Hi,
> 
> To my understanding Newlib defines the ANSI  implementation only  if the
> flag _HAVE_STDC defined , I  found only  few of the files covered under
> this.
> malloc(), labs() are not under this macro.
> 

The _HAVE_STDC flag is used to determine C coding.  For example, prototypes
are different under ANSI than under the older K&R style.  Newlib uses the macro
to ensure that newlib can be compiled with the C compiler being used.

The __STRICT_ANSI__ flag is used to hide various non-ANSI added declarations
from newlib header files that intrude on the user's namespace.

Newlib is ANSI plus added things from UNIX, C99, POSIX,
the Single Unix Specification, and various extensions like glibc extensions.
You don't turn on/off ANSI for newlib.

> On gcc compiler An application can be compiled with -ansi option enabled to
> confirm to  ANSI standard ,  To  measure if Newlib confirms  to the ANSI
> Should I apply the same here also ?
>

No, the option means:

`-ansi'
      In C mode, support all ANSI standard C programs.  In C++ mode,
      remove GNU extensions that conflict with ISO C++.

      This turns off certain features of GCC that are incompatible with
      ANSI C (when compiling C code), or of standard C++ (when compiling
      C++ code), such as the `asm' and `typeof' keywords, and predefined
      macros such as `unix' and `vax' that identify the type of system
      you are using.  It also enables the undesirable and rarely used
      ANSI trigraph feature.  For the C compiler, it disables
      recognition of C++ style `//' comments as well as the `inline'
      keyword.

      The alternate keywords `__asm__', `__extension__', `__inline__'
      and `__typeof__' continue to work despite `-ansi'.  You would not
      want to use them in an ANSI C program, of course, but it is useful
      done with `-ansi'.  Alternate predefined macros such as `__unix__'
      and `__vax__' are also available, with or without `-ansi'.

      The `-ansi' option does not cause non-ANSI programs to be rejected
      gratuitously.  For that, `-pedantic' is required in addition to
      `-ansi'.  *Note Warning Options::.

      The macro `__STRICT_ANSI__' is predefined when the `-ansi' option
      is used.  Some header files may notice this macro and refrain from
      declaring certain functions or defining certain macros that the
      ANSI standard doesn't call for; this is to avoid interfering with
      any programs that might use these names for other things.

      The functions `alloca', `abort', `exit', and `_exit' are not
      builtin functions when `-ansi' is used.

It cannot be used to validate if Newlib adheres to the
library portion of the standard, which is what you are looking for.

> My question is :
> Is newlib (either 1.10.0 / 1.11.0) Fully ANSI compliant ?

They are meant to be: referring to ANSI/ISO 9899-1990.  AFAIK, an ANSI C
conformance testsuite has never been run against newlib so I cannot say
with certainty that newlib is "fully" compliant.  This is free software.
If you know of a free ANSI C conformance testsuite, I will run newlib
through it.

> How about the coverage of  C99 standard ?

Newlib does not adhere to the C99 standard, although there are some C99 features
added.

-- Jeff J.



More information about the Newlib mailing list