Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (AndrewAMD, Quad, M_D), 1,217 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Unintialized array or dynamic pointer array #404489
07/09/12 21:50
07/09/12 21:50
Joined: Apr 2006
Posts: 159
Latvija
Arrovs Offline OP
Member
Arrovs  Offline OP
Member

Joined: Apr 2006
Posts: 159
Latvija
So in struct i could vish line like this:
Code:
BMAP* bmap_array[];


it gives erros - no idea vhat bad is in this. In C# its standart.
Code:
BMAP* bmap_array[10];


But this vorks - but i cant knov its length at moment so it sucks.

Code:
function blabla(var parameter)
{
BMAP* bmap_array[parameter];
}


And again. In function i cant initialize pointer array vith variable, but only vith handvritten number.
Vhat is difference - vhy it happens?
or im just too stupid to do things right?


Arrovs once will publish game
Re: Unintialized array or dynamic pointer array [Re: Arrovs] #404491
07/09/12 22:04
07/09/12 22:04
Joined: Feb 2009
Posts: 3,207
Germany, Magdeburg
Rei_Ayanami Offline
Expert
Rei_Ayanami  Offline
Expert

Joined: Feb 2009
Posts: 3,207
Germany, Magdeburg
This is the normal behavior in LiteC (and standard C).

You need to initialize your (dynamic) array by "malloc" (or sys_malloc).

Like, if you want to alloc space for 10 BMAP pointers:

BMAP **bmap_array = malloc(sizeof(BMAP*)*10);

Re: Unintialized array or dynamic pointer array [Re: Rei_Ayanami] #404492
07/09/12 22:22
07/09/12 22:22
Joined: Apr 2006
Posts: 159
Latvija
Arrovs Offline OP
Member
Arrovs  Offline OP
Member

Joined: Apr 2006
Posts: 159
Latvija
I vant something like in c#
int[] numbers = new int[5];
if it just could be
int[] numbers = sys_malloc(size_of(int)*5);
///
int numbers = sys_malloc(size_of(int)*5);
makes it just like one object and i cant make pointers to one from 5 made objects.
At least i didnt managed to do it vithout memory copying, but i dont vant to
double memory size if i can use pointer.

Ou, and thanks. I didnt knev about possibility to make pointer array.I vill try it out and im hoping it vorks good.


Arrovs once will publish game
Re: Unintialized array or dynamic pointer array [Re: Arrovs] #404493
07/09/12 22:23
07/09/12 22:23
Joined: Feb 2009
Posts: 3,207
Germany, Magdeburg
Rei_Ayanami Offline
Expert
Rei_Ayanami  Offline
Expert

Joined: Feb 2009
Posts: 3,207
Germany, Magdeburg
int[] numbers = new int[5];

is

int *numbers = sys_malloc(size_of(int)*5);

in LiteC wink

(You can access numbers like in C# then)

Re: Unintialized array or dynamic pointer array [Re: Rei_Ayanami] #404494
07/09/12 22:40
07/09/12 22:40
Joined: Apr 2006
Posts: 159
Latvija
Arrovs Offline OP
Member
Arrovs  Offline OP
Member

Joined: Apr 2006
Posts: 159
Latvija
Code:
#define jauns(struktura) sys_malloc(sizeof(struktura))
#define jauni(struktura,daudzums) sys_malloc(daudzums*sizeof(struktura))

typedef struct 
{
   int i;
}Str;

function main()
{
   Str* otrs;
Str* tress;
   Str* int_mas = jauni(Str, 10);
   int lok_i;
   for(lok_i = 0; lok_i<10; lok_i++)
   {
      int_mas[lok_i].i = lok_i;
   }
   otrs = int_mas;
tress = int_mass[0];//dont vork anymore
}


So this is all right?
Strange feeling about struct array vho already is throughout initialized.
But here is problem - i cant point out just to one element.
Its vhat i said - nov i need copy it and its so unright.

Last edited by Arrovs; 07/09/12 22:59.

Arrovs once will publish game
Re: Unintialized array or dynamic pointer array [Re: Arrovs] #404505
07/10/12 06:36
07/10/12 06:36
Joined: Sep 2007
Posts: 62
Germany
B
bodden Offline
Junior Member
bodden  Offline
Junior Member
B

Joined: Sep 2007
Posts: 62
Germany
tress is a pointer, int_mas[0] is not a pointer. try this:
Code:
#define jauns(struktura) sys_malloc(sizeof(struktura))
#define jauni(struktura,daudzums) sys_malloc(daudzums*sizeof(struktura))

typedef struct 
{
   int i;
}Str;

function main()
{
   Str* otrs;
	Str* tress;
   Str* int_mas = jauni(Str, 10);
   
   int lok_i;
   
   
   for(lok_i = 0; lok_i<10; lok_i++)
   {
      int_mas[lok_i].i = lok_i;
   }
   otrs = int_mas;
	tress = &int_mas[0];// <===== works now
	
	printf("tress.i: %.3f",(double)tress.i);
}



Re: Unintialized array or dynamic pointer array [Re: bodden] #404510
07/10/12 09:03
07/10/12 09:03
Joined: Aug 2007
Posts: 1,922
Schweiz
Widi Offline
Serious User
Widi  Offline
Serious User

Joined: Aug 2007
Posts: 1,922
Schweiz
Is your ,w' key on your keyboard brocken? wink

Edit: see the answer in another post from you.

Last edited by Widi; 07/10/12 09:06.

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1