On 09/08/2010 02:47 PM, Tor Didriksen wrote:
> On 2010-09-08 14:22, Mats Kindahl wrote:
>>>> One way to avoid the problems that Mark points out is to redefine
>>>> >> my_bool to be "int". This would work for all places where
>>>> my_bool is
>>>> >> used and IIRC, there are no places in ABIs where my_bool is
>>>> used. If
>>>> >> there are, it is easy to replace them with "unsigned char" to
>>>> ensure
>>>> >> that the ABI does not change.
>>>> >>
>>> > naah, I think we want sizeof(my_bool) == 1
>>>
>> Why?
>>
>> /Matz
>>
>>
> - save space
Hardly relevant in this case.
* If my_bool is used inside a structure, alignment on modern
architectures will force it to align on a 4-byte boundary anyway
* If several my_bool are used in a sequence, memory could be saved,
but if space is so important, it is better to use a bit field
* As return value they will not save space, and even generate larger
code. Not much, but it defuses the argument of saving space.
* As auto variables, they are likely to align at 4-byte boundaries
anyway, if they end up on the stack, and be stored in a register
if not.
> - compatibility with bool in C++ (and C99)
I cannot see at all why there is any advantage in allowing
sizeof(my_bool) == sizeof(bool). The type bool is used in C++ and
my_bool is used in C: there will not be a connection between them that
make any difference whatsoever.
>
> I encourage you to try 'typedef int my_bool;'
> my guess is you will get quite a few errors to fix, both compile time
> and run-time
Out of curiosity, I did.
* I found some violations of the ABI in that InnoDB uses "char" in
place of "my_bool", and same for the semi-sync plugin.
* I had to rewrite the Sys_var_mybool to Sys_var_bool instead (it's
C++ code and was using "my_bool" inside the class but "bool" for
the underlying variables, which cause the casting problems that
Mark was talking about).
That's all. I didn't run all tests, just the "main" test suite.
Patch attached for the curios. There is one change to the ABI, but that
is only because I just wanted the compile to pass. The ABI can be
maintained, but right now it's too late for me to bother about fixing
that for the demo patch.
Just my few cents,
Mats Kindahl
>
> -- didrik
>
>
Attachment: [text/x-diff] patch-1.diff
| Thread |
|---|
| • [STYLE] use true/false in C++, not TRUE/FALSE | Guilhem Bichot | 26 Aug |
| • Re: [STYLE] use true/false in C++, not TRUE/FALSE | Roy Lyseng | 26 Aug |
| • Re: [STYLE] use true/false in C++, not TRUE/FALSE | MARK CALLAGHAN | 26 Aug |
| • Re: [STYLE] use true/false in C++, not TRUE/FALSE | Guilhem Bichot | 31 Aug |
| • Re: [STYLE] use true/false in C++, not TRUE/FALSE | MARK CALLAGHAN | 31 Aug |
| • Re: [STYLE] use true/false in C++, not TRUE/FALSE | Guilhem Bichot | 31 Aug |
| • Re: [STYLE] use true/false in C++, not TRUE/FALSE | Jay Pipes | 31 Aug |
| • Re: [STYLE] use true/false in C++, not TRUE/FALSE | Davi Arnaut | 31 Aug |
| • Re: [STYLE] use true/false in C++, not TRUE/FALSE | Jay Pipes | 31 Aug |
| • Re: [STYLE] use true/false in C++, not TRUE/FALSE | Davi Arnaut | 31 Aug |
| • Re: [STYLE] use true/false in C++, not TRUE/FALSE | MARK CALLAGHAN | 31 Aug |
| • Re: [STYLE] use true/false in C++, not TRUE/FALSE | Davi Arnaut | 31 Aug |
| • Re: [STYLE] use true/false in C++, not TRUE/FALSE | MARK CALLAGHAN | 31 Aug |
| • Re: [STYLE] use true/false in C++, not TRUE/FALSE | Roy Lyseng | 31 Aug |
| • Re: [STYLE] use true/false in C++, not TRUE/FALSE | MARK CALLAGHAN | 31 Aug |
| • Re: [STYLE] use true/false in C++, not TRUE/FALSE | Michael Widenius | 8 Sep |
| • Re: [STYLE] use true/false in C++, not TRUE/FALSE | Jay Pipes | 8 Sep |
| • RE: [STYLE] use true/false in C++, not TRUE/FALSE | Vladislav Vaintroub | 31 Aug |
| • Re: [STYLE] use true/false in C++, not TRUE/FALSE | Roy Lyseng | 31 Aug |
| • Re: [STYLE] use true/false in C++, not TRUE/FALSE | Davi Arnaut | 31 Aug |
| • Re: [STYLE] use true/false in C++, not TRUE/FALSE | Michael Widenius | 8 Sep |
| • Re: [STYLE] use true/false in C++, not TRUE/FALSE | Davi Arnaut | 8 Sep |
| • RE: [STYLE] use true/false in C++, not TRUE/FALSE | Vladislav Vaintroub | 8 Sep |
| • Re: [STYLE] use true/false in C++, not TRUE/FALSE | Michael Widenius | 8 Sep |
| • Re: [STYLE] use true/false in C++, not TRUE/FALSE | Konstantin Osipov | 8 Sep |
| • Re: [STYLE] use true/false in C++, not TRUE/FALSE | Mats Kindahl | 8 Sep |
| • Re: [STYLE] use true/false in C++, not TRUE/FALSE | Tor Didriksen | 8 Sep |
| • Re: [STYLE] use true/false in C++, not TRUE/FALSE | Mats Kindahl | 8 Sep |
| • RE: [STYLE] use true/false in C++, not TRUE/FALSE | Vladislav Vaintroub | 8 Sep |
| • Re: [STYLE] use true/false in C++, not TRUE/FALSE | Mats Kindahl | 8 Sep |
| • Re: [STYLE] use true/false in C++, not TRUE/FALSE | Tor Didriksen | 8 Sep |
| • Re: [STYLE] use true/false in C++, not TRUE/FALSE | Mats Kindahl | 8 Sep |
| • Re: [STYLE] use true/false in C++, not TRUE/FALSE | Jay Pipes | 31 Aug |
| • Re: [STYLE] use true/false in C++, not TRUE/FALSE | Michael Widenius | 8 Sep |
| • Re: [STYLE] use true/false in C++, not TRUE/FALSE | MARK CALLAGHAN | 31 Aug |
| • Re: [STYLE] use true/false in C++, not TRUE/FALSE | Mats Kindahl | 27 Aug |
| • Re: [STYLE] use true/false in C++, not TRUE/FALSE | Michael Widenius | 8 Sep |