Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (dr_panther, 7th_zorro), 1,203 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
quick question about initializing structs #455679
10/27/15 12:07
10/27/15 12:07
Joined: Dec 2011
Posts: 1,823
Netherlands
Reconnoiter Offline OP
Serious User
Reconnoiter  Offline OP
Serious User

Joined: Dec 2011
Posts: 1,823
Netherlands
Hi,

If I do MY_STRUCT* my_structarray[20]; after setting up MY_STRUCT, will my_structarray[20] be set automatically to NULL?
So the following will not give me memory errors right? (just want to be sure):

Code:
function my_function()
{
...
  if (my_structarray[0] != NULL)
  {
    than do blablabla
  }
...
}



It seems like it has been set to NULL here. Cause otherwise I will manually set it to NULL in a for loop.

Last edited by Reconnoiter; 10/27/15 12:08.
Re: quick question about initializing structs [Re: Reconnoiter] #455680
10/27/15 12:40
10/27/15 12:40
Joined: Apr 2015
Posts: 20
Vietnam
F
Florastamine Offline
Newbie
Florastamine  Offline
Newbie
F

Joined: Apr 2015
Posts: 20
Vietnam
Yes.

Code:
#include <acknex.h>

typedef struct {
	int x;
	int y;
} data;

data *d;

int main()
{
	if( d == NULL ) printf("Caught!");
	
	return 0;
}



By the way, NULL is just a fancy name for (void *) 0 so you might want to do if(!my_structarray[0]) instead.

Re: quick question about initializing structs [Re: Florastamine] #455681
10/27/15 12:57
10/27/15 12:57
Joined: Dec 2011
Posts: 1,823
Netherlands
Reconnoiter Offline OP
Serious User
Reconnoiter  Offline OP
Serious User

Joined: Dec 2011
Posts: 1,823
Netherlands
tnx

Re: quick question about initializing structs [Re: Reconnoiter] #455765
10/29/15 12:24
10/29/15 12:24
Joined: Dec 2011
Posts: 1,823
Netherlands
Reconnoiter Offline OP
Serious User
Reconnoiter  Offline OP
Serious User

Joined: Dec 2011
Posts: 1,823
Netherlands
Hi,

Hmm this doesn't seem to work for me. In the code (2nd) below it should ignore empty places in my struct pointer with 2 arrays, but it doesn't (for some reason the struct pointer is not set to NULL), even when would manually set it to null:

Code:
...
MY_STRUCT* mystruct[20][20];

function struct_startup()
{
        //empty pointer first
	var i, j;
	for (i = 0; i < 20; i++)
	{  
		for (j = 0; j < 20; j++) mystruct[i][j] = NULL; 
	} 
	
	//than fill
        ...
}



no errors yet. And if I filter to struct that I have filled with real values it works fine to. But when I have set pointer to NULL only and switch to it through the code below; it gives an error (which it shouldn't cause it should detect that it is NULL & skip it in in the first place right??), the line with the break doesn't work well:

Code:
//store filter for 20 types
var filter[20] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };

function next_filter (var buttonnumber, PANEL* p_panelofbutton)
{
  //set to current type & filter
  var type = p_panelofbutton.skill_x; //e.g. 0
  var filter = filter[type]; //e.g. 1

                //till struct that is not NULL
		while(1)
		{
			filter[type] += buttonnumber * 2 - 3; //either +1 or -1
			if (filter[type] > 19) filter[type] = 0;
			if (filter[type] < 0) filter[type] = 19;	
			
			if (mystruct[type][filter] != NULL) break; //it always breaks here for some reason
                }		
  
  refresh_page(); //refresh a window with debug vars & digits etc.
}


Last edited by Reconnoiter; 10/29/15 12:33.

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