forward reference to structure

General discussion on mikroBasic PRO for dsPIC30/33 and PIC24.
Post Reply
Author
Message
peterverkaik
Posts: 174
Joined: 31 Aug 2009 22:44

forward reference to structure

#1 Post by peterverkaik » 08 Mar 2012 10:35

Hi,

I am using 2 structures, and each structure has a field that holds a pointer
to the other structure.

Code: Select all

structure A_
  dim _next as ^B 'error
end structure
typedef A as A_

structure B_
  dim info as ^A
end structure
typedef B as B_

The compiler complains at the marked line that B is undefined.
Since _next contains a pointer the size of A is known, even with B undefined at that time.

How can I make this work?

regards peter

peterverkaik
Posts: 174
Joined: 31 Aug 2009 22:44

Re: forward reference to structure

#2 Post by peterverkaik » 09 Mar 2012 16:46

Hi,

I found the keyword 'forward' so I tried

structure B_ forward
and
typedef B forward

but neither works.

I am actually converting a C program to Basic and
there are numerous circular references with pointers in structures
so I really need a way to do this or a workaround.

Anyone?

regards peter

User avatar
janko.kaljevic
Posts: 3565
Joined: 16 Jun 2011 13:48

Re: forward reference to structure

#3 Post by janko.kaljevic » 10 Mar 2012 16:06

Hello,

At the moment there is no way to do this in mikroBasic.
We are aware of this and we will provide solution as soon as possible.

Forward declaration will help you to declare procedures without following implementation.

Currently you can do this but it will require some modifications to your code.

Thanks for reporting this.

Best regards.

peterverkaik
Posts: 174
Joined: 31 Aug 2009 22:44

Re: forward reference to structure

#4 Post by peterverkaik » 11 Mar 2012 00:42

Hi,

I found a workaround by defining
dim _next as word 'dim _next as ^B

and using a helper variable
dim _next as ^B

in subroutines where I access B.

If you make 'forward' apply to types, we can use
typedef B forward

Also, type union would be useful besides structure.

regards peter

User avatar
janko.kaljevic
Posts: 3565
Joined: 16 Jun 2011 13:48

Re: forward reference to structure

#5 Post by janko.kaljevic » 12 Mar 2012 12:15

Hello,

type union is on our wishlist and we will implement it in some of the next releases.

Best regards.

Post Reply

Return to “mikroBasic PRO for dsPIC30/33 and PIC24 General”