[Top][All Lists]

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

Re: [Tinycc-devel] Merging patches...

From: Dave Dodge
Subject: Re: [Tinycc-devel] Merging patches...
Date: Tue, 10 Oct 2006 03:29:11 -0400
User-agent: Mutt/1.5.12-2006-07-14

On Sun, Oct 08, 2006 at 12:32:39AM -0400, Rob Landley wrote:
> I'm also currently squinting at:
> http://www.dododge.net/tcc/patches.html

> I'm still slightly fuzzy on the exact problem it's solving though,
> and avoid use of "const" in my own programs anyway.)

I use "const" pretty much anywhere I can.  My code is littered with it.

As to the tcc problem: I'll have a header file with a prototype for a
function that specifies parameter types but no parameter names:

  extern void foo(int,const char *);

I usually consider it bad style for a function to modify its
parameters (remember, I'm a const freak), so when I implement the
function and add the parameter names I mark them const.  This tells
the compiler that for optimization purposes it can assume the
parameter values will not change within the function, and that if I do
inadvertantly try to change them, it should tell me:

  void foo(int const a,const char * const s)
     /* If I try to do "a=0" or "s++" in here the compiler should complain */

The file that implements the function will include the header with the
prototype.  This is so that the compiler can tell me if I've screwed
up and the declaration doesn't match the definition.

The problem with tcc is that it thinks the above prototype doesn't
match the above definition, and it incorrectly flags a mismatch
between the header and the implementation.  C says that the constness
of the parameter is supposed to be ignored when comparing function
signatures, but tcc doesn't take that into account.

> whether the first patch in that list is sufficient considering
> is_compatible_types() can recurse when looking at a pointer but the
> flag to ignore "const" gets stripped off by the wrapper function so
> it only applies at the top level...

The N869 wording referenced in the patch talks about the qualifiers on
the parameter type, and I think that means that ignoring only the
top-layer const is sufficient.

                                                  -Dave Dodge

reply via email to

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