from C to C++

Peter Ingels (EBC) Peter.Ingels@ebc.ericsson.se
Mon Feb 3 14:59:00 GMT 2003


Hi,
I've inherited an old LAPD stack written in C and I'm trying to C++-ify it.
The old C stack uses a function pointer to keep track of the stack's state:

typedef (*Statptr)();
and the variable
Statptr Layer2State;

the Statptr variable points to functions that looks like e.g.:

Statptr  DLLpassive(MESSAGE* rx_sig_ptr);

That is the function itself returns a Statptr! I guess the C compiler isn't too fuzzy about type checking!? Any way, the "engine" of the state machine is then simply:

Layer2State = (Statptr) (*Layer2State) (mp);
where mp is the MESSAGE* arriving on the queue.

Now, the problem is that I can't port this scheme to C++. I'm thinking it's got be doable...

I ended up with:

typedef void* (LapdStack::*Statptr) (Message*);
the state functions (DLLpassive and so on) looks the same but the "engine" becomes:

Layer2State = (Statptr) ((this->*Layer2State)(mp));

This , however, doesn't compile. G++ 2.95.3 says:

/home/ebcinpe/clearcase/ebcinpe_view/mecs/egx/sw/dp/mg/mta/isdn_pri/lapd/src/Lap
dStack.cpp: In method `bool LapdStack::mainThreadWorker(IPC_Sig_t *)':
/home/ebcinpe/clearcase/ebcinpe_view/mecs/egx/sw/dp/mg/mta/isdn_pri/lapd/src/Lap
dStack.cpp:43: cannot convert `((LapdStack::Layer2State.void * (LapdStack::*)(Me
ssage *)::__index >= 0) ? (*(*(this + LapdStack::Layer2State.void * (LapdStack::
*)(Message *)::__pfn_or_delta2.{anonymous union}::__delta2) + ((LapdStack::Layer
2State.void * (LapdStack::*)(Message *)::__index * 4) + 0fffffffc))) : LapdStack
::Layer2State.void * (LapdStack::*)(Message *)::__pfn_or_delta2.{anonymous union
}::__pfn)((this + LapdStack::Layer2State.void * (LapdStack::*)(Message *)::__del
ta), mp_sig)' from type `void *' to type `void * (LapdStack::*)(Message *)'
make: *** [/home/ebcinpe/clearcase/ebcinpe_view/mecs/egx/sw/dp/mg/mta/isdn_pri/l
apd/obj/LapdStack.o] Error 1

The message is a bit suspicious looking but I guess the issue is 
"cannot convert from type `void *' to type `void * (LapdStack::*)(Message *)"

Can someone help me with this?
There are obviously some simple workarounds without function pointers, but I kind of like to keep them.

anyone?

/Peter




More information about the Gcc-help mailing list