From: "Peter Ingels (EBC)" <Peter.Ingels@ebc.ericsson.se>
To: "'gcc-help@gcc.gnu.org'" <gcc-help@gcc.gnu.org>
Cc: "Peter Ingels (EBC)" <Peter.Ingels@ebc.ericsson.se>
Subject: from C to C++
Date: Mon, 03 Feb 2003 14:59:00 -0000 [thread overview]
Message-ID: <836ADA7119C9D311A6AE0008C7E6A9A7048BB7BA@esealnt441> (raw)
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
next reply other threads:[~2003-02-03 14:59 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-02-03 14:59 Peter Ingels (EBC) [this message]
2003-02-03 15:16 ` Ben Davis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=836ADA7119C9D311A6AE0008C7E6A9A7048BB7BA@esealnt441 \
--to=peter.ingels@ebc.ericsson.se \
--cc=gcc-help@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).