small code C->FB

General FreeBASIC programming questions.
Post Reply
VANYA
Posts: 1850
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

small code C->FB

Post by VANYA »

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

Re: small code C->FB

Post by led-bloon »

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:

Re: small code C->FB

Post by TJF »

led-bloon translation is OK, but It's
  • map(100-1) AS A1
(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:

Re: small code C->FB

Post by VANYA »

led-bloon and TJF
thanks!
led-bloon
Posts: 33
Joined: Jan 06, 2010 8:16

Re: small code C->FB

Post by led-bloon »

Tks TJF - point taken
counting_pine
Site Admin
Posts: 6323
Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs

Re: small code C->FB

Post by counting_pine »

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

Re: small code C->FB

Post by fxm »

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:

Re: small code C->FB

Post by TJF »

@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:

Re: small code C->FB

Post by VANYA »

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
Post Reply