Skip to content

Differences from C90

Chris Feger edited this page Mar 11, 2020 · 3 revisions

How picoC differs from C90

picoC is a tiny C language, not a complete implementation of C90. It doesn't aim to implement every single feature of C90 but it does aim to be close enough that most programs will run without modification.

picoC also has scripting abilities which enhance it beyond what C90 offers.

C preprocessor

There is no true preprocessor in picoC. The most popular preprocessor features are implemented in a slightly limited way.

#define

define macros are implemented but have some limitations. They can only be used as part of expressions and operate a bit like functions. Since they're used in expressions they must result in a value.

#if / #ifdef / #else / #endif

The conditional compilation operators are implemented, but have some limitations. The operator "defined()" is not implemented. These operators can only be used at statement boundaries.

#include

include is supported however the level of support depends on the specific port of picoC on your platform. Linux/UNIX and cygwin support #include fully.

Function declarations

This style of function declaration is supported:

int my_function(char param1, int param2, char *param3) { ... }

The old "K&R" form of function declaration is not supported.

Predefined macros

A few macros are pre-defined:

  • picoC_VERSION - gives the picoC version as a string eg. "v2.1 beta r524"
  • LITTLE_ENDIAN - is 1 on little-endian architectures or 0 on big-endian architectures
  • BIG_ENDIAN - is 1 on big-endian architectures or 0 on little-endian architectures

Function pointers

Pointers to functions should be supported. If any issues are encountered, bring them up on the PKSM repository.

Storage classes

Many of the storage classes in C90 really only have meaning in a compiler so they're not implemented in picoC. This includes: static, extern, volatile, register and auto. They're recognised but currently ignored.

struct and unions

Structs and unions can only be defined globally. It's not possible to define them within the scope of a function.

Bitfields in structs are not supported.

Linking with libraries

Because picoC is an interpreter (and not a compiler) libraries must be linked with picoC itself. Also a glue module must be written to interface to picoC. This is the same as other interpreters like python.

If you're looking for an example check the interface to the C standard library time functions in cstdlib/time.c.

goto

The goto statement is implemented, but only supports forward gotos, not backward. The rationale for this is that backward gotos are not necessary for any "legitimate" use of goto.

Some discussion on this topic:

varargs

Passing arrays as pointers to variadic argument functions seems to be interestingly broken. The cause of this is currently unknown, but as a workaround, &array[0] may be passed instead