Subject:
|
Re: How to make shared memory....not
|
Newsgroups:
|
lugnet.robotics.rcx.legos
|
Date:
|
Thu, 27 Dec 2001 17:42:02 GMT
|
Viewed:
|
2060 times
|
| |
| |
I think this is what you want, but I am still learning. :)
int inc (int&);
int dec (int&);
int (*pFunc) (int); //pointer to a function that accepts/returns an int
if (add) {
pFunc = inc;
}
else {
pFunc = dec;
}
int a = pFunc(10);
So, if add is true, then pFunc points at the inc function. If it is false,
it points at the dec function. Then, you can call pFunc(10), and not worry
if you called inc or dec, as long as the arguments/return values are the
same. This can be modified into Michael's code to call functions from
different programs.
Can't you just link in a library/object file with all of your common
functions when you link the final source to be downloaded? I haven't used
legOS much, never could get it to work, but it seems like it would be
possible instead of messing with pointers and addresses that have the
potential to be incorrectly set.
Andy
----- Original Message -----
From: "Steve Hassenplug" <steveh@mailcode.com>
To: <lugnet.robotics.rcx.legos@lugnet.com>
Sent: Thursday, December 27, 2001 9:43 AM
Subject: Re: How to make shared memory....not
> In lugnet.robotics.rcx.legos, Michael Obenland writes:
> >
> > BTW., this scheme can be extended to something like a shared library. If you
> > store pointers to functions instead of ints, you can call a routine in
> > Program 1 from Program 2 or 3.
>
> ooohh. I like that idea. So I can write one program with all my functions
> and my other programs can just include a couple function calls.
>
> Again, in my VB world, I don't mess with pointers. When you have a minute,
> can you type up a sample function? (with a sample call)
>
> Thanks!
> Steve
|
|
Message has 1 Reply: | | Re: How to make shared memory....not
|
| (...) Yes, I'm sure I can. And I think it would be 'safer' that way. But Mike's idea about functions sounds interesting. I don't really have any idea about how I would use that in a real program, but it sure sounds interesting. Steve (23 years ago, 27-Dec-01, to lugnet.robotics.rcx.legos)
|
Message is in Reply To:
| | Re: How to make shared memory....not
|
| (...) ooohh. I like that idea. So I can write one program with all my functions and my other programs can just include a couple function calls. Again, in my VB world, I don't mess with pointers. When you have a minute, can you type up a sample (...) (23 years ago, 27-Dec-01, to lugnet.robotics.rcx.legos)
|
11 Messages in This Thread:
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
This Message and its Replies on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
|