tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] Look, Is this TCC's bug?


From: Rob Landley
Subject: Re: [Tinycc-devel] Look, Is this TCC's bug?
Date: Wed, 5 Sep 2007 13:32:17 -0500
User-agent: KMail/1.9.6

On Wednesday 05 September 2007 3:39:51 am ShangHongzhang 62185 wrote:
> HI, all
>
>   Given a statement like:
>
>   int a = 0;
>   ((void (*) ()) a) (1);

It's valid C89, if crazy.  What you did it typecast "a" to a function pointer, 
and then call it.  The function pointer you typecast it to has empty 
parentheses in its prototype, which defaults to "...", or varargs.  So you 
can feed it any arguments you like and it's up to the caller to interpret 
them.

I'm not sure how C99 treats empty parentheses, let's see...

> 6.7.5.3 #10
>  An identifier list declares only the identifiers of the parameters of the
> function. An empty list in a function declarator that is part of a
> definition of that function specifies that the function has no parameters.
> The empty list in a function declarator that is not part of a definition of
> that function specifies that no information about the number or types of
> the parameters is supplied.115)

It's tough going slogging through this dreck, but what it says (and the 
examples in #12 confirm) is that empty parentheses in function declarators 
equate to (void), but empty parentheses elsewhere (prototypes, function 
pointer typecasts) equate to (...).

So the behavior of gcc and tcc appears to be correct here.

>   we can easly known that there exist a error, as complained by MSVC: "void
> (__cdecl *)(void)': too many actual parameters", but TCC can compile these
> without any error!?

I don't own a copy of MSVC (or a copy of Windows, for that matter), but a 
Microsoft product being broken really doesn't come as a surprise...

Rob
-- 
"One of my most productive days was throwing away 1000 lines of code."
  - Ken Thompson.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]