NXC - addressOf and pointers
Re: NXC - addressOf and pointers
what is the advantage of doing it this way (which appears to be very complicated and slow) instead of using the pseudo-pass-by-reference method?
-
- Posts: 100
- Joined: 27 Dec 2010, 19:10
Re: NXC - addressOf and pointers
The advantage - no code advantage - but I think in 'C'. If all you have is a hammer - everything looks
like a nail. But I did get out my C++ books tonight to try to understand pass by reference. I will try it.
But, a question - in NXC, will this pass by reference work for variables local to a function, or only for
global variables? Thanks.
Regarding the comment about a second routine accessing a variable while the first routine might be
modifying it, I'm careful about how any globals are shared between tasks, and in my robots so far, I
haven't had 2 or more tasks doing similar jobs where they might use the same functions.
like a nail. But I did get out my C++ books tonight to try to understand pass by reference. I will try it.
But, a question - in NXC, will this pass by reference work for variables local to a function, or only for
global variables? Thanks.
Regarding the comment about a second routine accessing a variable while the first routine might be
modifying it, I'm careful about how any globals are shared between tasks, and in my robots so far, I
haven't had 2 or more tasks doing similar jobs where they might use the same functions.
Re: NXC - addressOf and pointers
it works for local and global variables from one task or function to any other function (the variables you pass by reference to the destination function of course are local in here).
I am always working with lots of tasks (10- 20) - be assured that there are ways to protect variables from being prematurely overwritten, so don't mind about that for the moment.
And don't mind that "pass-by-reference" actually works completely different in NXC, don't ask why and simply keep your eyes shut, just consider it to be a black box which appears to work like the "by-reference" way although it actually doesn't.
Umm - better forget my last sentence as well. :D
I am always working with lots of tasks (10- 20) - be assured that there are ways to protect variables from being prematurely overwritten, so don't mind about that for the moment.
And don't mind that "pass-by-reference" actually works completely different in NXC, don't ask why and simply keep your eyes shut, just consider it to be a black box which appears to work like the "by-reference" way although it actually doesn't.
Umm - better forget my last sentence as well. :D
Re: NXC - addressOf and pointers
I did kind of get bored with it.doc-helmut wrote:Although muntoo tried a little around faking pointers by arrays, but IIRC it was only tinkering^^ (no offense, muntoo )
@OP Basically, I was doing:
Code: Select all
byte stack[20000];
ID p = stack_malloc(100 * sizeof byte);
Commit to LEGO Mindstorms Robotics Stack Exchange:
bit.ly/MindstormsSE
Commit to LEGO Stack Exchange: bit.ly/Area51LEGOcommit
Who is online
Users browsing this forum: No registered users and 5 guests