Below are the major features/bugs/differences from C:
if
and while
are supported. The body
clauses must be surrounded by curly braces, even if there is one statement.
The following is not legal:
if (x == 10) // syntax error! y = x; while (x != 0) // syntax error! x = x - 1;The above would need to be rewritten as:
if (x == 10) { y = x; } while (x != 0) { x = x - 1; }Note that the commonly used dangling form of if-statement is illegal in C-- syntax:
if (foo) { // do one thing } else if (bar) { // do another thing } else { // do yet another thing }
extern
in a file that wishes to
reference it (as in regular C programs). Initializers are limited to
literal data of the allowed types (just ints and strings, see below).
Intializers may not be arbitrary expressions -- just literal
data! Here are some examples:
int i = -10; // initialize i to -10 int j = 0x1234abcd; // initialize j to 0x1234abcd char newline = 10; // a single character char* msg = "hello"; // an initialized message int* foobar = 24; // a pointer to address 24 char buffer[20]; // a buffer of 20 chars... int myInts[10]; // an array of 10 ints extern int* intArray; // an array defined elsewhere extern char gCH; // a character defined elsewhere
main() { char* msg = "hello there\n"; printString(msg); printInt(strlen(msg)); }
Function calls are not type checked -- that is, the number and types
of arguments do not need to match the number and type of parameters.
For this reason, while external functions are allowed, they do not
(should not) need to be declared as extern
. This lack of
inter-module checking obviates the need for header files. Cebollita
neither requires nor supports them.
To return a value from a function, the reserved word return
should be used.
NO OTHER OPERATORS (eg. ++, --, ^, &, |, etc) are supported.
fact(int n) { int result = 1; while (n != 0) { result = result * n; n = n - 1; } return result; } main() { int n = 9; int result = fact(n); printString("The factorial is: "); printInt(result); }The above program would need to be linked against a library that provides the I/O functions printString and printInt.