From acfb93a96fde1263e8bfd7580668efe1aee54678 Mon Sep 17 00:00:00 2001 From: lemon Date: Wed, 3 Dec 2025 17:30:20 +0100 Subject: c: allow redeclaration with K&R and non K&R prototypes --- c/c.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'c') diff --git a/c/c.c b/c/c.c index 36ef6d5..75c9795 100644 --- a/c/c.c +++ b/c/c.c @@ -231,13 +231,21 @@ redeclarationok(const struct decl *old, const struct decl *new) switch (old->scls) { case SCSTATIC: case SCEXTERN: - if (old->ty.t == TYARRAY && new->ty.t == TYARRAY + if (old->ty.bits == new->ty.bits) return 1; + if (old->ty.t != new->ty.t) return 0; + if (old->ty.t == TYARRAY /* allow 'int x[]; int x[100];' */ && typechild(old->ty).bits == typechild(new->ty).bits && (isincomplete(old->ty) || isincomplete(new->ty))) { return 1; } - /*fallthru*/ + if (old->ty.t == TYFUNC /* allow 'int f(); int f(int);' (some K&R) */ + && typedata[old->ty.dat].ret.bits == typedata[new->ty.dat].ret.bits + && (typedata[old->ty.dat].kandr || typedata[new->ty.dat].kandr)) + { + return 1; + } + return 0; case SCTYPEDEF: return old->ty.bits == new->ty.bits; } -- cgit v1.2.3