This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Warnings with __builtin_choose_expr & __builtin_types_compatible_p
- From: Ranko Zivojnovic <ranko at spidernet dot net>
- To: gcc-help at gcc dot gnu dot org
- Date: Sun, 08 Aug 2004 20:47:40 +0300
- Subject: Warnings with __builtin_choose_expr & __builtin_types_compatible_p
Greetings,
I'm not sure if I'm missing something: when I try to compile the below
test case I get:
[ranko@ranko-home tmp]% gcc -o test-case test-case.c
test-case.c: In function `main':
test-case.c:40: warning: passing arg 1 of `example_func2' from
incompatible pointer type
test-case.c:41: warning: passing arg 1 of `example_func1' from
incompatible pointer type
The code is correct and the correct functions do get executed. I would
like however to get rid of the false warnings during the compilation.
[ranko@ranko-home tmp]% ./test-case
in example_func1()
test: 0
in example_func2()
ts: 30
Thanks and best regards,
Ranko
[ranko@ranko-home tmp]% gcc -v
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix
--disable-checking --with-system-zlib --enable-__cxa_atexit
--host=i386-redhat-linux
Thread model: posix
gcc version 3.3.2 20031022 (Red Hat Linux 3.3.2-1)
/* test-case.c
*/
#include <stdio.h>
#include <stdlib.h>
typedef struct example {
int t1;
int t2;
int t3;
int t4;
} example_t;
unsigned long long
example_func1(unsigned long *ulp)
{
printf("in example_func1()\n");
return (0 + *ulp);
}
unsigned long long
example_func2(example_t *tp)
{
printf("in example_func2()\n");
return (unsigned long long)(tp->t1 + tp->t2 + tp->t3 + tp->t4);
}
#define example_def(x) \
__builtin_choose_expr( \
__builtin_types_compatible_p(typeof (x), unsigned long), \
example_func1(&(x)), \
__builtin_choose_expr( \
__builtin_types_compatible_p (typeof (x), example_t), \
example_func2(&(x)), abort()))
static unsigned long test = 0;
static example_t ts = { 2, 4, 8, 16 };
int
main(int argc, char *argv[])
{
printf("test: %llu\n", example_def(test));
printf("ts: %llu\n", example_def(ts));
return 0;
}
--
Ranko Zivojnovic,
IT Director/CTO ranko@spidernet.net
Spidernet Services Ltd., Tel: +357 22 844844
Nicosia, Cyprus FAX: +357 22 669470