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

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

Post by Dave Brillha » Wed, 26 Jan 1994 04:56:11



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.

Quote:>   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

// ====================================================================
//
// 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);

Quote:}

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

Quote:}

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

 
 
 

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

Post by Fergus Henders » Thu, 27 Jan 1994 00:38:24



>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.

Quote:>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.

--


 
 
 

1. Calling a C-function in a C++ program when c-function needs function pointer

I have some c-code I half to rewrite to c++ and in this proces I half to
make a function call from c++ to a c-function

I have declared the c-function in extern "C" and rewritten the C-functions
parameterlist to c++ style!

Here is the c-functions declaration:
int lmdif_(int (*fcn) (),integer *m,integer *n,doublereal *x,doublereal
*fvec,
 doublereal *ftol,doublereal *xtol,doublereal *gtol,integer *maxfev,
doublereal *epsfcn,doublereal *diag,integer *mode,doublereal *factor,integer
*nprint,
integer *info,integer *nfev,doublereal *fjac,integer *ldfjac,integer *ipvt,
doublereal *qtf,doublereal *wa1,doublereal *wa2,doublereal *wa3,doublereal
*wa4)

Here is the extern "C" declaration:

#ifndef CAL_MAIN_H_
#define CAL_MAIN_H_

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
 lmdif_(int (*fcn)(),integer *m,integer *n,doublereal *x,doublereal *fvec,
 doublereal *ftol,doublereal *xtol,doublereal *gtol,integer *maxfev,
doublereal *epsfcn,doublereal *diag,integer *mode,doublereal *factor,integer
*nprint,
integer *info,integer *nfev,doublereal *fjac,integer *ldfjac,integer *ipvt,
doublereal *qtf,doublereal *wa1,doublereal *wa2,doublereal *wa3,doublereal
*wa4);
 void  distorted_to_undistorted_sensor_coord (double Xd,double Yd,double
*Xu,double *Yu);
 void  distorted_to_undistorted_image_coord (double Xd,double Yd,double
*Xu,double *Yu);
#ifdef __cplusplus
#endif /* __cplusplus */

#endif /* !CALMAIN_H_ */

Here i a call of the c-function lmdif_():
    lmdif_ (cc_compute_exact_f_and_Tz_error,
            &m, &n, x, fvec, &ftol, &xtol, &gtol, &maxfev, &epsfcn,
            diag, &mode, &factor, &nprint, &info, &nfev, fjac, &ldfjac,
            ipvt, qtf, wa1, wa2, wa3, wa4);

I get the error that the first parameter in the call
cc_compute_exact_f_and_Tz_error of type void(long*, long*, double *, double
*) cannot be converted to int(__cdecl *)(void)

What can I do to remove the error?
Could I cast the parameret in the call to the type  "int(__cdecl *)(void)"
and how would I do this?

--
Benny Lund
Student at Computer Science
at Aalborg University


home phone: +4599348438

2. netscape 'funny' text

3. g++ 3.1: ISO C++ forbids casting between pointer-to-function and pointer-to-object

4. No Mouse on c64 GEOS

5. Audio CD quality when mastering from MP3s?

6. ANSI C/C++ function prototypes for XLib, Xt

7. Matlab as server ?

8. how to define a pointer to a function returning function pointer?

9. casting pointer to member function to pointer to base class member function

10. Function Pointers and Member Function Pointers

11. const function and function prototype

12. const function & function prototype: answers