This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

When C++ obeject is passed to C function


Hello All,

     I have come across a situation where I need to map a C structure of
function pointers to C++ virtual table pointers. Using padding I able to map
this. Now my problem is inspite of proper mapping the sample is dumping core
when tried to call the function. Here is the gdb output which depicts more
clearly whats happening

===========================================================================================================
(gdb) run
Starting program: /reference/vtable/linux_ia64-g/vtable

Breakpoint 1, main () at cppfile.cxx:8
8               myDerived a;
(gdb) n
11              a.Release( );
(gdb) n
in Release
12              a.f1(g);
(gdb) n
into f1
13              a.f2("dkfj");
(gdb) n
into f2, dkfj
14              call_cplusplus(&a);
(gdb) s
call_cplusplus (p=0x80000fffffffb4c0) at cfile.c:11
11        p->lpVtbl->AddRef(p);
Current language:  auto; currently c
(gdb) p * p->lpVtbl
$1 = {QueryInterface = 0x4000000000001150 <myDerived::QueryInterface(_GUID
const&, void**)>, wupad1 = 6917529027641088424,
  AddRef = 0x40000000000011e0 <myDerived::AddRef()>, wupad2 =
6917529027641088424,
  Release = 0x4000000000000f40 <myDerived::Release()>, wupad3 =
6917529027641088424,
  f1 = 0x4000000000000fb0 <myDerived::f1(_GUID const&)>, wupad4 =
6917529027641088424,
  f2 = 0x4000000000001030 <myDerived::f2(char*)>, wupad5 = 6917529027641088424,
  f3 = 0x4000000000001250 <myDerived::f3(unsigned long)>, wupad6 =
6917529027641088424,
  f4 = 0x40000000000012e0 <myDerived::f4(unsigned short, unsigned short)>}
(gdb) p p->lpVtbl->AddRef(p)
in AddRef
$2 = 0
(gdb) n
11        p->lpVtbl->AddRef(p);
(gdb) n

Program received signal SIGILL, Illegal instruction.
0x5800a191800 in ?? ()
(gdb)

==============================================================================================================

     Can somebody tell me whats going wrong or am I missing something??
     Any help will be really appreciated.

Thanks in advance
-Vallabha



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]