scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit 94615c26e61ff331100b39816cf2b4ea82dc4bd7
parent cdafe864ddbdca6af43660f88bff661afb6b42de
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Wed, 16 Apr 2014 11:48:40 +0200

Add void pointers

These pointers can be mixed with pointers of any type.

Diffstat:
Mcc.h | 2+-
Mexpr.c | 3+++
Mtypes.c | 6++++++
3 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/cc.h b/cc.h @@ -113,7 +113,7 @@ extern void context(void (*fun)(void)); extern Type *typename(void); -extern Type *voidtype, *booltype, +extern Type *voidtype, *pvoidtype, *booltype, *uchartype, *chartype, *uinttype, *inttype, *ushortype, *shortype, diff --git a/expr.c b/expr.c @@ -117,6 +117,9 @@ convert(Node *np, Type *tp1) switch (t2) { case ARY: case FTN: np = addr2ptr(np); + case PTR: + if (tp1 != pvoidtype && tp2 != pvoidtype) + return NULL; /* TODO: * we assume conversion between pointers * do not need any operation, but due to diff --git a/types.c b/types.c @@ -13,6 +13,10 @@ Type .op = VOID, .letter = 'W' }, + *pvoidtype = &(Type) { + .op = PTR, + .letter = 'R' + }, *booltype = &(Type) { .op = INT, .letter = 'B', @@ -139,6 +143,8 @@ mktype(Type *tp, uint8_t op, register Type *bp; char letter; + if (op == PTR && tp == voidtype) + return pvoidtype; t = (op ^ (uint8_t) ((unsigned short) tp >> 3)) & NR_TYPE_HASH-1; tbl = &typetab[t];