Topic: GNU C++ 2.5.7 BUG?: Pointer to Function Prototype Check


Author: dbrillha@dave.mis.semi.harris.com (Dave Brillhart)
Date: Mon, 24 Jan 1994 19:56:11 GMT
Raw View
I tried this on Sun (cfront 3.0), Borland and Symantic compilers.
All 3 compilers give an error at the following line in the included
test program, but GNU C++ 2.5.7 happily accepts it.

>   function_pointer = print_int;

Has anyone else seen this problem with GNU C++? I'm new to GNU
compilers - will I run across a lot of bugs using them?

Regards,

Dave Brillhart
dbrillha@harris.com


// ====================================================================
//
// Here is another interesting problem. Again, I believe it is
// a compiler 'bug'. Please note that 'function_pointer' is defined
// by the prototype to take a FLOAT parameter. At compile time,
// should not the compiler detect the invalid assignment of
// function_pointer to print_int? Garbage results at run-time.
//
// ====================================================================
//
#include <stdio.h>
#include <iostream.h>

void print_float(float ff);
void print_int(int ii);
void (*function_pointer)(float);

main()
{
   float pf  = 3.14;
   int   pi  = 314;

   print_float(pf);
   function_pointer = print_float;
   function_pointer(pf);

   print_int(pi);
   function_pointer = print_int;
   function_pointer(pi);
}

void print_float(float ff)
{
   printf("Print_float function: %f\n",ff);
}

void print_int(int ii)
{
   cout << "Print_int function: " << ii << "\n";
}




Author: fjh@munta.cs.mu.OZ.AU (Fergus Henderson)
Date: Tue, 25 Jan 1994 15:38:24 GMT
Raw View
dbrillha@dave.mis.semi.harris.com (Dave Brillhart) writes:

>I tried this on Sun (cfront 3.0), Borland and Symantic compilers.
>All 3 compilers give an error at the following line in the included
>test program, but GNU C++ 2.5.7 happily accepts it.
>
>void print_int(int ii);
>void (*function_pointer)(float);
...
>>   function_pointer = print_int;

Yes, this is a bug.

>Has anyone else seen this problem with GNU C++? I'm new to GNU
>compilers - will I run across a lot of bugs using them?

That depends.  GNU C++ is still rather buggy.  GNU C is quite
reliable.

--
Fergus Henderson - fjh@munta.cs.mu.OZ.AU