NiceC is an improved version of ANSI C. It attempts to clean up C as much as possible using syntax translation. A type checker for NiceC is under development. The NiceC programming language is translated to, and fully compatible with, ordinary C. Thus it can be used as a drop-in replacement for C. The main benefits of using NiceC are as follows:

Cleaned-up type syntax: Types read left to right, instead of inside out. For example, the type “function taking a pointer to int and returning int” reads *int->int instead of int (*) (int*).

Enhanced readability: By judicious use of keywords, NiceC improves readability and eliminates semicolons in many cases where C requires them.

Automatic generation of header files: In NiceC, the programmer usually doesn't have to write header files. Instead, the programmer writes implementation files, and the compiler automatically generates the corresponding headers. Definitions marked private are excluded from the generated headers.

Smart import expansion: Header files are imported via an import command. The compiler remembers which files it has imported and ignores duplicates, so there is no need for include guards.

Symbolic constants: NiceC provides named compile-time constants; for example, constant PI = 3.14159. A NiceC constant becomes a #define directive in the C output, but the constant expression is parsed (providing syntax checking at the point of definition), and the syntax is more pleasant.

Hierarchical namespaces: NiceC provides a simple namespace hierarchy. Code can appear in scoped namespaces called modules, which can be arbitrarily nested. Symbols declared or defined in a module are mangled in the C output by prepending the names of all the enclosing namespaces.

Generic programming: NiceC provides an elegant way to do type-safe generic programming. For example, one can write a type-generic data structure such as a list or map without using void*. The implementation is a thin layer on top of the C preprocessor, but the syntax is much cleaner.

The NiceC compiler is written in Standard ML of New Jersey (SML/NJ), which is freely available. The compiler should run on any UNIX-like system with SML/NJ installed. The generated C should compile and run on any system with a C compiler.

This work was done by Robert L. Bocchino of Caltech for NASA's Jet Propulsion Laboratory. This software is available for license through the Jet Propulsion Laboratory, and you may request a license here . NPO-49579


Tech Briefs Magazine

This article first appeared in the February, 2018 issue of Tech Briefs Magazine.

Read more articles from this issue here.

Read more articles from the archives here.