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: Tue, 6 Nov 2012 12:55:27 +0000

Cool, thanks. I'll keep an eye on it

On 5 November 2012 22:21, Hitoshi Mitake <address@hidden> wrote:
> On Tue, Nov 6, 2012 at 5:28 AM, Rob <address@hidden> wrote:
>> 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 for your interest :)
> I'm hosting my tcc here, and I'll push the change to this branch:
> https://github.com/mitake/tinycc/tree/struct-cmp
> I've not implemented the feature yet, but my work in progress will appear 
> here.
>
> Thanks,
>
> --
> Hitoshi Mitake
> address@hidden
>
> _______________________________________________
> Tinycc-devel mailing list
> address@hidden
> https://lists.nongnu.org/mailman/listinfo/tinycc-devel



reply via email to

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