PropGCC equivalent of someVar := long[someAddress]?
JonnyMac
Posts: 9,107
As I stumble around PropGCC I found a bit of code that looks like this
I'm assuming that an address can be passed in *par -- how can I extract that like I would with long[parVal] in Spin?
void blinker(void *par) { while(1) { high(26); pause(1000); low(26); pause(1000); } }
I'm assuming that an address can be passed in *par -- how can I extract that like I would with long[parVal] in Spin?
Comments
In my code, I usually define a struct to hold all the data I want to pass via par, and then pass a pointer to that struct in.
I use the C++ feature of PropGCC, and that's a really handy way to pass an entire object to the new cog. I use it like this:
main.cpp:
MyClass.h:
The problem with cogstart for C++ is that C++ class members have an implicit *this, which is lost with the cogstart. So, you have to cogstart a little runner function.
The only difference is you need to cast void *par. As long as you always agree on the type (like in spin), it can be anything including a pointer to a structure, a pointer to a pointer, a pointer to an array, or single number.
This line "int ledarray = { 26, 1000 };"
should be "volatile int ledarray[] = { 26, 1000 };"
Sorry, I'm a little sick this weekend.
Using volatile says: "Look compiler, I don't care if you think what I'm doing with ledarray is wasteful. Do what I want."
int ledarray[] needs brackets [] to declare it an array. The brackets can have a number. I.E. int ledarray[2] = { 26, 1000 };