public inbox for insight@sourceware.org
 help / color / mirror / Atom feed
* Problems with function pointers in C++
@ 2008-02-17 14:40 Geert Vancompernolle
  2008-02-17 19:38 ` Keith Seitz
  0 siblings, 1 reply; 23+ messages in thread
From: Geert Vancompernolle @ 2008-02-17 14:40 UTC (permalink / raw)
  To: Insight Foum

Hi,

Using Insight 6.7.1, compiled for the host i686-pc-linux-gnu and for the 
target cris-axis-linux-gnu

I have the following (educational) piece of code (c) Lars Haendel 
(http://www.newty.de):

#include "stdio.h"

#include <stdlib.h>
#include <iostream>
using namespace std;

class TMyClass
{
public:
    int DoIt( float a, char b, char c )
    {
        cout << "TMyClass::DoIt" << endl;
        return ( (int)a + b + c);
    }
   
    int DoMore( float a, char b, char c ) const
    {
        cout << "TMyClass::DoMore" << endl;
        return ( (int)a - b + c );
    }
};

int DoIt( float a, char b, char c )
{
    printf( "DoIt\n");
    return ( (int)a + b + c );
}

int DoMore( float a, char b, char c ) //const
{
    printf( "DoIt\n");
    return ( (int)a - b + c );
}

int main( int argc, const char **argv )
{
    int (*pt2Function)( float, char, char ) = NULL;
    int (TMyClass::*pt2Member)( float, char, char ) = NULL;
    int (TMyClass::*pt2ConstMember)( float, char, char ) const = NULL;
   
    pt2Function = DoIt;
    //pt2Function = &DoMore;
   
    pt2ConstMember = &TMyClass::DoMore;
    pt2Member      = &TMyClass::DoIt;
   
    if ( pt2Function > 0 )
    {
        if ( pt2Function == &DoIt )
        {
            printf( "Pointer points to DoIt\n" );
        }
        else
        {
            printf( "Pointer not initialized\n" );
        }
    }
   
    int result1 = pt2Function( 12, 'a', 'b' );
    printf( "Result 1 = %d\n", result1 );
    int result2 = (*pt2Function)( 12, 'a', 'b' );
    printf( "Result 2 = %d\n", result2 );
   
    TMyClass instance1;
    int result3 = (instance1.*pt2Member)( 12, 'a', 'b' );
    printf( "Result 3 = %d\n", result3 );
    // int result4 = (*this.*pt2Member)( 12, 'a', 'b' );
    // printf( "Result 4 = %d\n", result4 );
   
    TMyClass* instance2 = new TMyClass;
    int result4 = (instance2->*pt2Member)( 12, 'a', 'b' );
    printf( "Result 4 = %d\n", result4 );
    int result5 = (instance2->*pt2ConstMember)( 12, 'a', 'b' );
    printf( "Result 5 = %d\n", result5 );
    delete instance2;
       
    return( 0 );
}


When using Insight to step through the code, I can step without problems 
into the "C" function pointers (pt2Function and *pt2Function) using the 
"S" command.

However, when trying to use the same "S" command when the C++ function 
pointers are handled, the debugger refuses to step into the functions 
"DoIt" and "DoItMore" from the class TMyClass.  Even stepping over the 
call (using "N") does not work.
I have to put a breakpoint just after the calls (on the lines containing 
the printf statements) and press "C" to continue debugging.

The results, however, are fine.  The program itself works perfect, only 
Insight can apparently not "follow" C++ function pointers.

Any ideas?

-- 
*Best rgds,

--Geert
*

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

end of thread, other threads:[~2008-02-24 18:34 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-02-17 14:40 Problems with function pointers in C++ Geert Vancompernolle
2008-02-17 19:38 ` Keith Seitz
2008-02-18  4:03   ` Geert Vancompernolle
2008-02-18  4:07     ` Geert Vancompernolle
2008-02-18  7:09       ` Keith Seitz
2008-02-19 18:51         ` Geert Vancompernolle
2008-02-19 19:00           ` Geert Vancompernolle
2008-02-19 19:20           ` Geert Vancompernolle
2008-02-19 19:59             ` Keith Seitz
2008-02-20 18:24               ` Geert Vancompernolle
2008-02-20 19:03                 ` Keith Seitz
2008-02-20 19:30                   ` Geert Vancompernolle
2008-02-20 19:35                     ` Keith Seitz
2008-02-20 19:48                       ` Geert Vancompernolle
2008-02-20 19:53                         ` Keith Seitz
2008-02-21 18:58                           ` Geert Vancompernolle
2008-02-21 19:04                             ` Keith Seitz
2008-02-21 19:33                             ` Geert Vancompernolle
2008-02-21 19:49                               ` Keith Seitz
2008-02-22 18:09                                 ` Geert Vancompernolle
2008-02-22 19:53                                   ` Keith Seitz
2008-02-24 10:03                                     ` Geert Vancompernolle
2008-02-24 18:34                                       ` Keith Seitz

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