cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: s/bool/int

From: Tor Arntsen <tor_at_spacetec.no>
Date: Wed, 26 May 2010 13:29:23 +0200

On Wed, May 26, 2010 at 12:50, Kamil Dudka <kdudka_at_redhat.com> wrote:

> Could you please compare your results with the example I posted?
>
> http://curl.haxx.se/mail/lib-2010-05/0288.html
>
> What exactly differs?

Ah, ok - your example shows that it will accept 2 as input and handle
it as 1, in a sense. I was looking for a compiler warning.

gcc -Wall, in any case (4.4.4 on my local machine) doesn't seem to
care much even for enum errors.

icc, on the other hand, is better at enums but not at C99 bools. This
little silly test tries to catch both things:

--
#include <stdbool.h>
#define TRUE 1
#define FALSE 0
typedef enum {
        bool_false = 0,
        bool_true  = 1
} new_bool;
int main (void)
{
        bool a;
        new_bool b;
        a = 1;
        a = true;
        a = false;
        a = TRUE;
        a = FALSE;
        a = 2;
        b = 1;
        b = 0;
        b = bool_false;
        b = bool_true;
        b = 2;
        (void)&(a);
        (void)&(b);
        return (0);
}
--
$ gcc -Wall -c test-bool.c
$
$ icc -Wall -c test-bool.c
test-bool.c(23): warning #188: enumerated type mixed with another type
        b = 1;
          ^
test-bool.c(24): warning #188: enumerated type mixed with another type
        b = 0;
          ^
test-bool.c(27): warning #188: enumerated type mixed with another type
        b = 2;
-Tor
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html
Received on 2010-05-26