From a75c394b2a36e7a1c8d4e338aa6dd33720601675 Mon Sep 17 00:00:00 2001 From: SantriptaSharma Date: Wed, 6 Dec 2023 14:12:22 +0530 Subject: [PATCH] fix (types): allow void pointers and correctly treat array pointers --- 15_A5.y | 2 +- 15_A5_translator.c | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/15_A5.y b/15_A5.y index 12e28e9..b066a3f 100644 --- a/15_A5.y +++ b/15_A5.y @@ -523,7 +523,7 @@ declaration: break; } - if ($1 == VOID_T && $$.sym->type.kind != FUNC_T) { + if ($1 == VOID_T && $$.sym->type.kind != FUNC_T && $$.sym->type.kind != PRIMITIVE_PTR && $$.sym->type.kind != ARRAY_PTR) { yyerror("void is zero-sized!"); YYABORT; } diff --git a/15_A5_translator.c b/15_A5_translator.c index 4ad2137..32461e3 100644 --- a/15_A5_translator.c +++ b/15_A5_translator.c @@ -324,10 +324,14 @@ int GetSize(Type type) { break; case PRIMITIVE_PTR: - case ARRAY_PTR: return size_of_pointer; break; + // semantically make more sense as pointer arrays and not array pointers, sorry + case ARRAY_PTR: + return size_of_pointer * type.array.size; + break; + case ARRAY_T: return Sizes[type.array.base] * type.array.size; break;