tinycc-devel
[Top][All Lists]
Advanced

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

Re: [Tinycc-devel] [PATCH v3] forbid invalid comparison of struct


From: Rob
Subject: Re: [Tinycc-devel] [PATCH v3] forbid invalid comparison of struct
Date: Mon, 5 Nov 2012 20:28:54 +0000
User-agent: Mutt/1.5.21 (2010-09-15)

On Mon, Nov 05, 2012 at 11:19:00PM +0900, Hitoshi Mitake wrote:
> On Mon, Nov 5, 2012 at 11:04 PM, Thomas Preud'homme <address@hidden> wrote:
> > Le lundi 5 novembre 2012 14:53:16, Hitoshi Mitake a écrit :
> >> Of course, comparison between different typed structs or structs and
> >> scalar typed values should cause compile error. But I feel that if we
> >> can write comparison between same struct typed values with ==
> >> operator, a compiler will be very useful. Because we can avoid the
> >> possibility of passing wrong value as 3rd parameter of memcmp().
> >
> > memcmp is not what you want because if a structure contains padding you are
> > not sure of its content. Therefore two structures could be identical with
> > different content inside the padding. You must compare field by field. 
> > That's why
> > assignement is possible but not equality: assignment is ok because you can
> > copy the padding so memcpy will give a valid copy of the structure. 
> > Comparing
> > with memcpy on the other hand will return false for some equal structures.
> 
> Ah, I missed about the padding... As you say, memcmp() is not a stuff for the
> above situation.

I had never thought of that, interesting edge case.


> >> The standard of C doesn't allow this behaviour. But I think it may be
> >> worth implementing it on TCC. Can TCC accept this behaviour as
> >> implementation specific dialect?
> >
> > From http://bellard.org/tcc/ :
> >
> > UNLIMITED! Any C dynamic library can be used directly. TCC is heading 
> > torward
> > full ISOC99 compliance. TCC can of course compile itself.
> >
> > I don't think we should not follow C99 on this.
> >
> 
> OK, I understand the direction of TCC.
> I'll implement == for field by field comparison only for my toy if I'll do :)
> 
> Thanks,

Regardless, I'd be interested in seeing your branch of tcc if you have it
hosted anywhere?


Thanks,
Rob



reply via email to

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