public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* warning when using __builtin_types_compatible_p
@ 2008-07-28 11:43 Manish Verma
  2008-07-28 11:59 ` John Love-Jensen
  0 siblings, 1 reply; 2+ messages in thread
From: Manish Verma @ 2008-07-28 11:43 UTC (permalink / raw)
  To: gcc-help

Hi all,

  I get a warning regarding the incompatible pointer type, when I
compile a very simple program at the bottom of this email. I must be
doing something very silly. Does anybody an idea about it? Thank you
very much.

Regards,
Manish

> foo.c: In function `main':
> foo.c:16: warning: passing arg 1 of `foo_float' from incompatible pointer type


#define foo(x) ({ if (__builtin_types_compatible_p(typeof(x),int*))
foo_int(x); else foo_float(x);})

void foo_int(int* a) {
    printf("a=%d\n", (*a+1));
}

void foo_float(float* a) {
    printf("b=%f\n",(*a+1.0));
}

int main() {
    int a = 10;
    float b = 101;
    foo(&a);
    return 0;
}

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: warning when using __builtin_types_compatible_p
  2008-07-28 11:43 warning when using __builtin_types_compatible_p Manish Verma
@ 2008-07-28 11:59 ` John Love-Jensen
  0 siblings, 0 replies; 2+ messages in thread
From: John Love-Jensen @ 2008-07-28 11:59 UTC (permalink / raw)
  To: Manish Verma, GCC-help

Hi Manish,

>   I get a warning regarding the incompatible pointer type, when I
> compile a very simple program at the bottom of this email. I must be
> doing something very silly. Does anybody an idea about it?

The foo_float routine takes a float*, but you are passing in an int*, which
is an incompatible type.

Expanding your main, this is what it looks like:

int main()
{
 int a = 10;
 float b = 101;
 {
  if(__builtin_types_compatible_p(typeof(&a), int*))
   foo_int(&a);
  else
   foo_float(&a); // <-- warning here
 }
 return 0;
}

It appears that you want to use some sort of function overloading.  I
suggest you use C++ as a "better C" compiler, so you can use the function
overloading feature present in C++, rather than try to mimic that C++
obfuscation feature in C.

HTH,
--Eljay

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2008-07-28 11:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-07-28 11:43 warning when using __builtin_types_compatible_p Manish Verma
2008-07-28 11:59 ` John Love-Jensen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).