From b9990d2c392c0dde1ff6e0cb6ed99b813982c5aa Mon Sep 17 00:00:00 2001 From: "zik.saleeba" Date: Mon, 9 Mar 2009 00:43:31 +0000 Subject: [PATCH] Functions returning void fixed git-svn-id: http://picoc.googlecode.com/svn/trunk@176 21eae674-98b7-11dd-bd71-f92a316d2d60 --- TODO | 1 + parse.c | 6 +++--- tests/07_function.c | 7 +++++++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/TODO b/TODO index 0c63ecd..c3df2d8 100644 --- a/TODO +++ b/TODO @@ -10,6 +10,7 @@ Bugs: } return (i * fact(i - 1)); } +* something wrong with interactive mode after error handling - not clearing token buffer correctly? Implement: * operator precedence diff --git a/parse.c b/parse.c index 2609760..cc41ec8 100644 --- a/parse.c +++ b/parse.c @@ -100,9 +100,6 @@ void ParseDeclaration(struct ParseState *Parser, enum LexToken Token) do { TypeParseIdentPart(Parser, BasicType, &Typ, &Identifier); - if (Token == TokenVoidType && Identifier != StrEmpty) - ProgramFail(Parser, "can't define a void variable"); - if ((Token != TokenVoidType && Token != TokenStructType && Token != TokenUnionType) && Identifier == StrEmpty) ProgramFail(Parser, "identifier expected"); @@ -113,6 +110,9 @@ void ParseDeclaration(struct ParseState *Parser, enum LexToken Token) ParseFunctionDefinition(Parser, Typ, Identifier, FALSE); else { + if (Token == TokenVoidType && Identifier != StrEmpty) + ProgramFail(Parser, "can't define a void variable"); + if (LexGetToken(Parser, NULL, FALSE) != TokenAssign) VariableDefine(Parser, Identifier, VariableAllocValueFromType(Parser, Typ, TRUE, NULL)); else diff --git a/tests/07_function.c b/tests/07_function.c index f2b91eb..64950d2 100644 --- a/tests/07_function.c +++ b/tests/07_function.c @@ -6,3 +6,10 @@ int myfunc(int x) printint(myfunc(3)); printint(myfunc(4)); +void vfunc(int a) +{ + printf("a=%d\n", a); +} + +vfunc(1234); +