Using startKIT ADC and Flash in the same application

All technical discussions and projects around startKIT
gkrusi
Junior Member
Posts: 7
Joined: Mon May 26, 2014 10:32 pm

Post by gkrusi »

alfanick, would you be ready to post your changed code here?

Thank you,
Gregor Krušič


robertxmos
XCore Addict
Posts: 169
Joined: Fri Oct 23, 2015 10:23 am

Post by robertxmos »

As resource in your code are implemented as opaque pointers (think void*), I would discourage the use of pointers when passing them around.

Resources should be passed by value (the opaque resource handle).

N.B. 'chan' and 'interface' are declarations that give you an implicit pair of handles of connected-resouce-ends for passing by value viz: 'interface client', 'interface server' 'chanend'.
They should be viewed as handy ways to declare paired resources but not resources themselves!
(The syntax is not nice as there implicit coercion going on - sorry)

If you are passing resources by value in a way the compiler can't check you are safe (e.g via global variables), use 'unsafe' viz:
unsafe chanend gc;
unsafe void foo(chanend c) { gc = c; } // copy opaque resource handle.

Only use pointers if you really want the address of a resource's handle and make sure it does not go out of scope and leave you with a dangling pointer viz:
chanend * unsafe pc;
unsafe void foo(chanend c) { pc = &c; } // oops, variable 'c' has gone!
Post Reply