suggestions for const structures

Coding and general discussion relating to the compiler

Moderators: David Barker, Jerry Messina

Post Reply
Jerry Messina
Swordfish Developer
Posts: 1473
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

suggestions for const structures

Post by Jerry Messina » Thu Dec 02, 2010 6:42 pm

Ideally, I'd like to declare an array of const structures to hold some different setup information, something like...

Code: Select all

structure mystruct_t
	b as byte
	w as word
	lw as longword
end structure

const setup_data() as mystruct_t =
	(
		(1, 1000, 10000),		// first struct
		(2, 2000, 20000),		// second struct
		(3, 3000, 30000)		// third struct
	)
	
This doesn't actually work, as const only works with the fundamental data types, and not structures.

The only method I could come up with to try and replicate this was to declare const arrays for each of the individual structure members, so the "structure array initialization" is spread over a few separate declarations...

Code: Select all

structure mystruct_t
	b as byte
	w as word
	lw as longword
end structure

// const arrays for each of the individual structure members
const MAX_STRUCTURES = 3
const cs_member_b(MAX_STRUCTURES) as byte = (1, 2, 3)					// init data for mystruct_t().b
const cs_member_w(MAX_STRUCTURES) as word = (1000, 2000, 3000)			// init data for mystruct_t().w
const cs_member_lw(MAX_STRUCTURES) as longword = (10000, 20000, 30000)	// init data for mystruct_t().lw


// example loop to get the values of each of the "const structures"

dim t as mystruct_t 
dim i as byte

for i = 0 to (MAX_STRUCTURES-1)
	t.b = cs_member_b(i)
	t.w = cs_member_w(i)	
	t.lw = cs_member_lw(i)	
next
Can anyone suggest a better/different way of doing this? It works, but it's not my first choice (if I have one, that is).

User avatar
kanderson
Posts: 17
Joined: Tue Oct 15, 2013 4:28 pm
Location: Canada
Contact:

Any luck?

Post by kanderson » Fri Nov 22, 2013 11:54 pm

Hi Jerry,

Have you found any better way to do it since your post? I also want to do something similar...

Jerry Messina
Swordfish Developer
Posts: 1473
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Post by Jerry Messina » Sat Nov 23, 2013 12:51 pm

Not really, Kane. I used the method shown.

It ends up being workable... just not as clear as having all the structure data together.

SHughes_Fusion
Posts: 219
Joined: Wed Sep 11, 2013 1:27 pm
Location: Chesterfield

Re: suggestions for const structures

Post by SHughes_Fusion » Fri Apr 11, 2014 3:14 pm

Bump - any plans to implement this or any better ways to achieve it?

I am trying to define a set of valid XML tags along with options associated with each tag and a reference ID. It would be much easier if I can define these in the same place rather than having to set up 3 arrays, especially when I currently have 37 commands and will probably be adding more. Lots of scope for getting things mixed up...

User avatar
David Barker
Swordfish Developer
Posts: 1214
Joined: Tue Oct 03, 2006 7:01 pm
Location: Saltburn by the Sea, UK
Contact:

Re: suggestions for const structures

Post by David Barker » Fri Apr 11, 2014 3:19 pm

There are no plans to implement this feature at the present time.

SHughes_Fusion
Posts: 219
Joined: Wed Sep 11, 2013 1:27 pm
Location: Chesterfield

Re: suggestions for const structures

Post by SHughes_Fusion » Fri Apr 11, 2014 3:20 pm

Thanks for the prompt reply, David.

Out of interest, are there any changes planned for Swordfish or have you moved on to other projects and the only updates we'll see are bug-fixes?

User avatar
David Barker
Swordfish Developer
Posts: 1214
Joined: Tue Oct 03, 2006 7:01 pm
Location: Saltburn by the Sea, UK
Contact:

Re: suggestions for const structures

Post by David Barker » Fri Apr 11, 2014 3:27 pm

Yes, I always have a list of things I would like to do, time permitting. As you have pointed out, bug fixes are a priority and I think many users appreciate the stability of Swordfish.

Post Reply