Pointer to structure not recognised in parent code?
bob_g4bby
Posts: 523
I'm writing a buffer based driver for the HDaudio add-in kit. But I'm having trouble with pointers to structures. I bet it's a simple nooby's mistake. In the driver I have the following code:-
sigbuff mic1
sigbuff mic2
sigbuff linein1
sigbuff linein2
sigbuff lineout1
sigbuff lineout2
^sigbuff micbuff
^sigbuff lineinbuff
^sigbuff lineoutbuff
^long micsample
^long lineinsample
^long lineoutsample
pri changebuffers()
if buffercycle <> false
buffercycle := false
[micbuff] := @mic1
[micsample] := @mic2
[lineinbuff] := @linein1
[lineinsample] := @linein2
[lineoutbuff] := @lineout1
[lineoutsample] := @lineout2
else
buffercycle := true
[micbuff] := @mic2
[micsample] := @mic1
[lineinbuff] := @linein2
[lineinsample] := @linein1
[lineoutbuff] := @lineout2
[lineoutsample] := @lineout1
cogatn(buffchangealert) ' send ATN to all cogs runnning dsp to signal it's time to start a fresh cycle
' at 48 ksample/s that cycle time is 21.333 mS - to do all dsp
There are two buffer sets. So every time an input buffer becomes full of samples from the a/d, the buffer set is swapped over in method changebuffers. e.g. pointer micbuff either points to mic1 or mic2 buffer etc.
If I write in the library, the statement 'lineoutbuff := micbuff' the compiler seems to accept that.
However, in the parent file that instantiates the library as 'sigpump': If I write 'sigpump.lineoutbuff := sigpump.micbuff' , the compiler complains 'Expected an object constant, structure or method'
What needs changing so that latter statement is also accepted?
Hope I've shown enough for someone to spot the mistook. I can post the whole project if need be.
Cheers, Bob

Comments
Is it simply the case that no variable declared in a library can be accessed directly from the main program, but can only be read and written via suitable get/set methods?
Maybe not - Is it the case that a variable declared in a library can be used globally throughout a program unless declared 'static', in which case the variable's scope is limited to the file it's defined in.
With FlexSpin at least, I think if you want to use a pub/pri local instance of a structure that's defined in a child object file, you have to first use a syntax like:
obj child: "child.spin2" con struct lineoutbuff = child.lineoutbuffThen you can use it as if it were defined in the current file. It does seem to be accepted without that if you declare it in a VAR block like:
obj child: "child.spin2" var child.lineoutbuff some_other_nameAlthough it seems like it won't accept it if the instance is named the same as the structure definition name (IOW, it doesn't seem to like:
var child.lineoutbuff lineoutbuff)Cheers
@avsa242 , I haven't got your suggestion to work. Here's a simple top level program with the compile fault in main:-
'' File .......... toplevel.spin2 '' Version........ 1 '' Purpose........ test scope of variables defined in library '' Author......... Bob Edwards '' Email.......... bob.edwards50@yahoo.com '' Started........ 26/1/2026 '' Latest update.. / / ''============================================================= {Spin2_v50} CON {timing constants} _xinfreq = 20_000_000 _clkfreq = 180_000_000 CON {fixed IO pins} CON {application IO pins} CON {Enumerated constants} CON {Data Structure definitions} struct mic1 = lib.mic1 struct lineout1 = lib.lineout1 CON { global constants } OBJ {Child Objects} lib : "library" VAR {Variable Declarations} {Public / Private methods} pub main() lineout1 := mic1Here's the library that toplevel uses:-
'' File .......... library.spin2 '' Version........ 1 '' Purpose........ test of scope of variable defined here '' Author......... Bob Edwards '' Email.......... bob.edwards50@yahoo.com '' Started........ 26/1/2026 '' Latest update.. / / ''============================================================= CON {timing constants} CON {fixed IO pins} CON {application IO pins} CON {Enumerated constants} CON {global constants} sigbuffsize = 1024 ' size of the iq signal buffers CON {Data Structure definitions} STRUCT sample(real, imag) ' one signal sample STRUCT sigbuff( sample iqsample [sigbuffsize] ) ' array of samples CON { global constants } OBJ {Child Objects} VAR {Variable Declarations} sigbuff mic1 sigbuff lineout1 {Public / Private methods} pub main()