[pulseaudio-discuss] Use 'bool' internally and 'int32_t' for ABI compatibility

Felipe Contreras felipe.contreras at gmail.com
Sun Jun 7 01:31:57 PDT 2009


On Sun, Jun 7, 2009 at 2:16 AM, Lennart
Poettering<lennart at poettering.net> wrote:
> On Sun, 07.06.09 02:10, Felipe Contreras (felipe.contreras at gmail.com) wrote:
>
>> >> >> #if HAVE_STDBOOL_H
>> >> >> #include <stdbool.h>
>> >> >> #else
>> >> >> typedef int bool
>> >> >> #endif
>> >> >>
>> >> >> And s/pa_bool_t/bool/
>> >> >>
>> >> >> If you have C99, pa_bool_t = _Bool, bool = _Bool
>> >> >> If you don't: pa_bool_t = int, bool = int
>> >> >
>> >> > The big issue is that you would change the ABI depending on the
>> >> > compiler used. That sucks.
>> >>
>> >> Yeah, but according to what you pasted you are already doing that;
>> >> sometimes pa_bool_t is _Bool, and sometimes it's int, right?
>> >
>> > Yes, but only internally. The internal ABIs don't matter, they are not
>> > built with different compilers, it doesn't matter if the size/encoding
>> > of things changes when you switch compilers or the configuration.
>> >
>> > However, when you export something in the public ABI you need to make
>> > sure it's the same on all compilers with all configurations.
>>
>> I don't think you are getting what I'm saying; I'm proposing to
>> replace 'pa_bool_t' with 'bool'. 'pa_bool_t' is used only internally,
>> therefore I'm proposing to use 'bool' only internally.
>
> Hmm, you just want to rename the internal type? What would the benefit
> of that be?

Readability. At least to me bool is easier to read than pa_bool_t, not
to mention that it's part of the C99 spec.... in any case, it was just
a suggestion.

Now, regarding the ABI compatibility it's not really safe to assume
that 'int' will always be of the same size in the same platform, a new
version of the compiler might use a different size, or a different
compiler might be used.

If you *really* want to make sure the size is the same you should use
int32_t which has other advantages; the size over the network in
different platforms will be the same, and algorithms can be sure of
the maximum number representable in the variable.

Of course, you would have to check for stdint.h, if the compiler
doesn't have that you would need to define int32_t yourself.

Cheers.

-- 
Felipe Contreras



More information about the pulseaudio-discuss mailing list