Question about use of bool in asan_interface.h

Hi,

I am trying to make use of the ASAN callbacks from C. However,
asan_interface.h uses bool in the public interface. This type has "only"
been introduced in C99. Unfortunately for me this means I have it not
available.

Is it sufficient to do something like:

# if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L)
    typedef unsigned char bool;
# endif
# include<sanitizer/asan_interface.h>

or would this break anything? If it breaks something, what alternatives
do I have if I cannot use C99 mode?

Thanks,

// Oliver

[sorry for late response]
Yea… I think we should simply change bool to int in the headers.
Let me see if this is going to break something…
Meanwhile, i’d expect that your hack is going to work fine.

–kcc

And #include <stdbool.h> doesn’t work?

Most pre-C99 environments had that header.

-Fil

Yea... I think we should simply change bool to int in the headers.
Let me see if this is going to break something...

What about autotesting public headers for compatibility with C99 in `make check-asan'?

$ gcc -c -std=c99 sanitizer/asan_interface.h -I.
sanitizer/asan_interface.h:53:3: error: unknown type name ‘bool’
sanitizer/asan_interface.h:66:40: error: unknown type name ‘bool’
sanitizer/asan_interface.h:88:3: error: unknown type name ‘bool’
sanitizer/asan_interface.h:98:3: error: unknown type name ‘bool’

-Y

You need stdbool.h to use bool with C99 - the keyword is called _Bool (unlike C++, C doesn't reuse valid identifiers as keywords in new versions. Unfortunately, it also doesn't provide a single c99.h / c11.h for turning all of the new keywords into their non-ugly versions, but I digress).

The FreeBSD stdbool.h, an old version of which ships with OS X, defines _Bool to int in stdbool.h for C89, but this is non-standard behaviour. GNU libc, for example, does not do this.

Including stdbool.h in asan_interface.h would fix the issue for C99, but not for C89 (in a portable way).

David

Hi Kostya,

thanks for the response. Cool. Was just unsure whether I'd have to
expect some unforeseen and unintended consequences.

I wasn't sure it was intentional or not, but since Clang accepts older C
dialects, I presumed it's somewhat unintentional.

Thanks again and have a nice weekend,

// Oliver

r206160 should fix this; let’s see if it sticks…