General FreeBASIC programming questions.
VANYA
Posts: 1850 Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:
Post
by VANYA » Apr 20, 2013 6:47
How does this translate to properly FreeBasic?
Code: Select all
struct A {
int B;
struct {
unsigned char D;
signed char F;
} map[100];
};
led-bloon
Posts: 33 Joined: Jan 06, 2010 8:16
Post
by led-bloon » Apr 20, 2013 7:26
Maybe this:
Code: Select all
TYPE A1
D AS UBYTE
F AS BYTE
END TYPE
TYPE A
B AS integer
map(100) AS A1
END TYPE
GL
lefty led
TJF
Posts: 3809 Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:
Post
by TJF » Apr 20, 2013 8:35
led-bloon translation is OK, but It's
(This may be important if the upper bound of the array is used somewhere in the code.)
VANYA
Posts: 1850 Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:
Post
by VANYA » Apr 20, 2013 8:42
led-bloon and TJF
thanks!
counting_pine
Site Admin
Posts: 6323 Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs
Post
by counting_pine » Apr 20, 2013 15:43
I suggest '0 to 100-1', to distinguish it from the C-style array format.
'0 to n-1' is a good idiom to get used to in BASIC - it's handy in array declarations and For loops.
fxm
Moderator
Posts: 12528 Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE
Post
by fxm » Apr 20, 2013 16:13
Or that other (except if the strucure must be a single block of memory):
Code: Select all
TYPE A1
D AS UBYTE
F AS BYTE
END TYPE
TYPE A
B AS integer
map AS A1 PTR = NEW A1[100]
DECLARE DESTRUCTOR ()
END TYPE
DESTRUCTOR A ()
DELETE THIS.map
END DESTRUCTOR
Otherwise:
Code: Select all
TYPE A1
D AS UBYTE
F AS BYTE
END TYPE
TYPE A
B AS integer
DECLARE PROPERTY map () AS A1 PTR
Private:
map0(0 TO 100-1) AS A1
END TYPE
PROPERTY A.map () AS A1 PTR
PROPERTY = @THIS.map0(0)
END PROPERTY
TJF
Posts: 3809 Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:
Post
by TJF » Apr 20, 2013 20:37
@fxm
If VANYA is talking about a header translation then your code wont be helpful (it wont work).
VANYA
Posts: 1850 Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:
Post
by VANYA » Apr 21, 2013 2:45
TJF wrote: @fxm
If VANYA is talking about a header translation then your code wont be helpful (it wont work).
Yes, I translation the header. But thanks anyway fxm.
Please, who knows C and is able to work with MinGW, see
this topic