cproc

Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.nihaljere.xyz/cproc
Log | Files | Refs | Submodules | README | LICENSE

commit 863af085d91310e25f9ec892adb93b412253e833
parent 1712e38057b824f79002011f0ca074b802f9b953
Author: Michael Forney <mforney@mforney.org>
Date:   Thu, 18 Apr 2019 13:02:29 -0700

Add some documentation about implemented extensions

Diffstat:
MREADME.md | 9++++++---
Adoc/extensions.md | 62++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 68 insertions(+), 3 deletions(-)

diff --git a/README.md b/README.md @@ -1,7 +1,9 @@ [![builds.sr.ht status](https://builds.sr.ht/~mcf/cc.svg)](https://builds.sr.ht/~mcf/cc) -This is a C11 compiler using [QBE] as a backend. It is released under the -[ISC] license. +This is a [C11] compiler using [QBE] as a backend. It is released under +the [ISC] license. + +Several GNU C [extensions] are also implemented. There is still much to do and some parts of the code are a little rough, but it currently implements most of the language, is self-hosting, @@ -12,7 +14,7 @@ It was inspired by several other small C compilers including [8cc], ## Requirements -The compiler itself is written in standard [C11] and can be built with +The compiler itself is written in standard C11 and can be built with any conforming C11 compiler. The POSIX driver depends on POSIX.1-2008 interfaces, and the `Makefile` @@ -71,6 +73,7 @@ Please report any issues to https://todo.sr.ht/~mcf/cc-issues. [QBE]: https://c9x.me/compile/ [C11]: http://port70.net/~nsz/c/c11/n1570.html [ISC]: https://git.sr.ht/~mcf/cc/blob/master/LICENSE +[extensions]: https://git.sr.ht/~mcf/cc/tree/master/doc/extensions.md [8cc]: https://github.com/rui314/8cc [c]: https://github.com/andrewchambers/c [scc]: http://www.simple-cc.org/ diff --git a/doc/extensions.md b/doc/extensions.md @@ -0,0 +1,62 @@ +# Extensions + +In addition to C11, several [GNU extensions] are implemented and more +may be implemented in the future. + +## Implemented + +### [`__typeof__`] + +`__typeof__(E)` is a type specifier for the type of expression `E`. Arrays +and function designator expressions do not decay into pointers, just +like when used with `sizeof`. + +### Built-in functions and types + +- **`__builtin_alloca`**: Allocate memory on the stack. +- **`__builtin_constant_p`**: Test whether the argument is a constant expression. +- **`__builtin_inff`**: `float` positive infinity value. +- **`__builtin_nanf`**: `float` quiet NaN value. +- **[`__builtin_offsetof`]**: Return the offset of a member in a struct or union. +- **`__builtin_types_compatible_p`**: Test whether the two types are compatible. +- **`__builtin_va_arg`**: Built-in suitable for implementing the `va_arg` macro. +- **`__builtin_va_copy`**: Built-in suitible for implementing the `va_copy` macro. +- **`__builtin_va_end`**: Built-in suitible for implementing the `va_end` macro. +- **`__builtin_va_list`**: Built-in suitable for implementing the `va_list` type. +- **`__builtin_va_start`**: Built-in suitable for implementing the `va_start` macro. + +## Missing + +### [Statement expressions] + +In GNU C, you may use a compound statement as expressions when they are +enclosed in parentheses. The last statement in the compound statement +must be an expression statement, whose value is used as the result of +the statement expression. + +### Empty declarations + +GNU C allows empty top-level declarations (i.e. `;`). + +### Empty initializer list + +GNU C allows empty initializer lists when initializing an object, +for example + +```c +struct { + int a, b; +} s = {}; +``` + +This behaves exactly the same as `{0}`. + +### Missing operand in conditional expression + +GNU C allows you to omit the second operand in conditional expressions, +in which case the first operand is used. So `E1 ? : E2` behaves the same +as `E1 ? E1 : E2`, except that `E1` is evaluated only once. + +[GNU extensions]: https://gcc.gnu.org/onlinedocs/gcc/C-Extensions.html +[`__typeof__`]: https://gcc.gnu.org/onlinedocs/gcc/Typeof.html +[Statement expressions]: https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html