Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
M1 Oversampling
by jcl. 04/26/24 11:12
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
Eigenwerbung
by jcl. 04/26/24 11:08
MT5 bridge not working on MT5 v. 5 build 4160
by EternallyCurious. 04/25/24 20:49
Trading Journey
by howardR. 04/24/24 20:04
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Scripts not found
by juergen_wue. 04/20/24 18:51
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (AndrewAMD, wandaluciaia, 1 invisible), 798 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
wandaluciaia, Mega_Rod, EternallyCurious, howardR, 11honza11
19049 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Accessing T6 struct leads to a crash? #485132
01/26/22 17:35
01/26/22 17:35
Joined: Jul 2017
Posts: 784
Z
Zheka Offline OP
User
Zheka  Offline OP
User
Z

Joined: Jul 2017
Posts: 784
This leads to a crash:
Code
int main() {
			
	T6* t;	
		
	t->fHigh =1;	
	
	return 1;
}
Why would this be?

Last edited by Zheka; 01/26/22 17:36.
Re: Accessing T6 struct leads to a crash? [Re: Zheka] #485133
01/26/22 18:08
01/26/22 18:08
Joined: Feb 2017
Posts: 1,725
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,725
Chicago
Your pointer is not pointing to a valid memory region.

Re: Accessing T6 struct leads to a crash? [Re: Zheka] #485134
01/26/22 18:15
01/26/22 18:15
Joined: Jul 2017
Posts: 784
Z
Zheka Offline OP
User
Zheka  Offline OP
User
Z

Joined: Jul 2017
Posts: 784
yyyes, memory should be allocated, of course...Tx!

Re: Accessing T6 struct leads to a crash? [Re: Zheka] #485136
01/26/22 18:35
01/26/22 18:35
Joined: Jul 2017
Posts: 784
Z
Zheka Offline OP
User
Zheka  Offline OP
User
Z

Joined: Jul 2017
Posts: 784
Code
#include <default.c>
#include <stdio.h>

int main() {
	
	T6* t = malloc(sizeof(T6));	
	
	DATE ttime  = dmy(20170101);
	
	t->time = ttime; // UTC timestamp of the close, DATE format
	  
	t->fHigh =1;
        t->fLow =1; 
        t->fOpen =1; 
        t->fClose=1; 
	t->fVal=0;
	t->fVol=0; // additional data, ask-bid spread, volume etc.

   //FILE* f = fopen("C:\\Zorro\\History\\USD_t.t6","w");
	
	//if (f) fwrite(t,sizeof(T6),1,f);
	
	//fclose(f);
	
	free(t);
	
	return 0;
}
and this gives a "can't open clib.dll"...

Re: Accessing T6 struct leads to a crash? [Re: Zheka] #485138
01/26/22 21:10
01/26/22 21:10
Joined: Feb 2017
Posts: 1,725
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,725
Chicago
No need to call malloc or low-level file functions, just use datasets. T6 is a seven-field dataset (where element 0 is the timestamp and also the beginning of the struct).

dataStr can be used to return a pointer to your T6 struct.
Quote
For storing complex data such as structs, use a sufficient record size plus 8 bytes for the timestamp, and copy the struct to dataStr(Handle,Record,1). If a separate timestamp is not needed, or if it is part of the struct as for the T1..T8 structs, the struct can be stored to dataStr(Handle,Record,0).
https://www.zorro-project.com/manual/en/data.htm

Re: Accessing T6 struct leads to a crash? [Re: Zheka] #485141
01/27/22 01:15
01/27/22 01:15
Joined: Jul 2017
Posts: 784
Z
Zheka Offline OP
User
Zheka  Offline OP
User
Z

Joined: Jul 2017
Posts: 784
Fine, i am aware of that. But do you know the reason for "cant' open clib.dll" in the example above (with file-related functions commented out)?

Re: Accessing T6 struct leads to a crash? [Re: Zheka] #485142
01/27/22 12:22
01/27/22 12:22
Joined: Feb 2017
Posts: 1,725
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,725
Chicago
No. I don't get this error on 2.45.8.

EDIT: Oh, but I get it on 2.46.2. That's a bug with the stdio.h header.

Last edited by AndrewAMD; 01/27/22 13:07.
Re: Accessing T6 struct leads to a crash? [Re: Zheka] #485143
01/27/22 13:18
01/27/22 13:18
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
The stdio.h file has some lines inside that don't belong in that file. If you want, you can remove all lines with a "clib" and also the corresponding function prototypes. That will fix the error.

In C you need no malloc or datasets for a single struct. Just define it.

T6 t ;
t.time = ttime;

malloc or datasets are used when you need large arrays of structs.

Re: Accessing T6 struct leads to a crash? [Re: jcl] #485145
01/27/22 14:03
01/27/22 14:03
Joined: Jul 2017
Posts: 784
Z
Zheka Offline OP
User
Zheka  Offline OP
User
Z

Joined: Jul 2017
Posts: 784
Originally Posted by jcl
The stdio.h file has some lines inside that don't belong in that file. If you want, you can remove all lines with a "clib" and also the corresponding function prototypes. That will fix the error.
Ok, i will. So those will be removed in the next update?


Moderated by  Petra 

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