public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* from C to C++
@ 2003-02-03 14:59 Peter Ingels (EBC)
  2003-02-03 15:16 ` Ben Davis
  0 siblings, 1 reply; 2+ messages in thread
From: Peter Ingels (EBC) @ 2003-02-03 14:59 UTC (permalink / raw)
  To: 'gcc-help@gcc.gnu.org'; +Cc: Peter Ingels (EBC)

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


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

end of thread, other threads:[~2003-02-03 15:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-02-03 14:59 from C to C++ Peter Ingels (EBC)
2003-02-03 15:16 ` Ben Davis

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