[Top][All Lists]

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

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

From: Thomas Preud'homme
Subject: Re: [Tinycc-devel] [PATCH v3] forbid invalid comparison of struct
Date: Mon, 5 Nov 2012 15:04:48 +0100
User-agent: KMail/1.13.7 (Linux/3.2.0-4-amd64; KDE/4.8.4; x86_64; ; )

Le lundi 5 novembre 2012 14:53:16, Hitoshi Mitake a écrit :
> Thanks, I committed the change on the mob branch.


> BTW, I've intended to implement comparison between structs
> originally. And I found the bug accidentally.

As I reviewed your patch and realized it's correct and I was wrong ;)

> 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 
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.

> 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.

Best regards,

Thomas Preud'homme

Attachment: signature.asc
Description: This is a digitally signed message part.

reply via email to

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