cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: s/bool/int

From: Kamil Dudka <kdudka_at_redhat.com>
Date: Wed, 26 May 2010 13:49:38 +0200

On Wed May 26 2010 13:29:23 Tor Arntsen wrote:
> 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.

gcc does not check for enum conversions by default, g++ does. Nevertheless
the enum enabled sparse catches these issues fairly well:

$ sparse test.c
test.c:23:13: warning: conversion of
test.c:23:13: int to
test.c:23:13: int enum new_bool
test.c:24:13: warning: conversion of
test.c:24:13: int to
test.c:24:13: int enum new_bool
test.c:27:13: warning: conversion of
test.c:27:13: int to
test.c:27:13: int enum new_bool
test.c:21:13: warning: cast truncates bits from constant value (2 becomes 0)

> 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

Why not the following instead?

#define TRUE bool_true
#define FALSE bool_false

Kamil
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2010-05-26