Gamestudio Links
Zorro Links
Newest Posts
Trading Journey
by howardR. 04/24/24 20:04
M1 Oversampling
by Petra. 04/24/24 10:34
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Data from CSV not parsed correctly
by EternallyCurious. 04/20/24 21:39
Scripts not found
by juergen_wue. 04/20/24 18:51
zorro 64bit command line support
by 7th_zorro. 04/20/24 10:06
StartWeek not working as it should
by jcl. 04/20/24 08:38
folder management functions
by VoroneTZ. 04/17/24 06:52
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (sleakz, AndrewAMD), 684 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Mega_Rod, EternallyCurious, howardR, 11honza11, ccorrea
19048 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
lite-C bug #467822
09/03/17 13:05
09/03/17 13:05
Joined: Aug 2017
Posts: 58
P
pascalx Offline OP
Junior Member
pascalx  Offline OP
Junior Member
P

Joined: Aug 2017
Posts: 58
Guys. Why?
http://www.zorro-trader.com/manual/en/apointer.htm

Code:
struct S
{
	int* P;
};

void main()
{
	struct S s;
	s.P = malloc(sizeof(int));
	*(s.P) = 1234; // Ok
	s.P[0] = 1234; // Error: subscript requires array or pointer type
	int* p = s.P;
	p[0] = 2345; // Ok
	printf("%d", *(s.P));
	free(s.P);
}


Re: lite-C bug [Re: pascalx] #467823
09/03/17 13:30
09/03/17 13:30
Joined: Feb 2017
Posts: 1,725
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,725
Chicago
This doesn't work in normal C either. (Whoops, yes it does.)

Code:
s.P = malloc(sizeof(int));



(C++) Visual Studio says...
"a value of type "void *" cannot be assigned to an entity of type "int *"

Last edited by AndrewAMD; 09/04/17 16:41.
Re: lite-C bug [Re: AndrewAMD] #467824
09/03/17 13:57
09/03/17 13:57
Joined: Aug 2017
Posts: 58
P
pascalx Offline OP
Junior Member
pascalx  Offline OP
Junior Member
P

Joined: Aug 2017
Posts: 58
Originally Posted By: AndrewAMD
This doesn't work in normal C either.

s.P = malloc(sizeof(int));

Visual Studio says...
"a value of type "void *" cannot be assigned to an entity of type "int *"

Sounds like you compiled with C++ compiler.
C performs an implicit cast, whereas C++ requires an explicit cast for void* (static_cast<int*>)

Compiles in C

Code:
#include <stdlib.h>
#include <stdio.h>

struct S
{
	int* P;
};

int main()
{
	struct S s;
	s.P = malloc(sizeof(int));
	*(s.P) = 1234; // Ok
	s.P[0] = 1234; // Ok
	int* p = s.P;
	p[0] = 2345; // Ok
	printf("%d", *(s.P));
	free(s.P);
	return 0;
}


Last edited by pascalx; 09/03/17 14:40.
Re: lite-C bug [Re: pascalx] #467826
09/03/17 14:28
09/03/17 14:28
Joined: Aug 2017
Posts: 58
P
pascalx Offline OP
Junior Member
pascalx  Offline OP
Junior Member
P

Joined: Aug 2017
Posts: 58
Another Error. Or maybe just unsupported.

Code:
#define ARRAY_SIZE 10

int array1[10]; // Ok
int array2[ARRAY_SIZE]; // Ok
int array3[ARRAY_SIZE+1]; // Error

void main()
{
}


Last edited by pascalx; 09/03/17 14:40.
Re: lite-C bug [Re: pascalx] #467834
09/03/17 22:15
09/03/17 22:15
Joined: Aug 2017
Posts: 58
P
pascalx Offline OP
Junior Member
pascalx  Offline OP
Junior Member
P

Joined: Aug 2017
Posts: 58
Honestly guys, what kind of sorcery is this...

Code:
void f1()
{
	return 0; // compiles fine
}

int f2()
{
	return; // compiles fine
}



And this

Code:
void f()
{
	printf("A");
}

void f() // Ok
{
	printf("B");
}

void run()
{
	if(is(FIRSTRUN))
	{
		f(); // prints "B"
	}
}


Last edited by pascalx; 09/03/17 22:21.
Re: lite-C bug [Re: pascalx] #467835
09/04/17 00:16
09/04/17 00:16
Joined: Aug 2017
Posts: 58
P
pascalx Offline OP
Junior Member
pascalx  Offline OP
Junior Member
P

Joined: Aug 2017
Posts: 58
Code:
void main()
{
	const int i = 5;
	i = 6; // Ok
	printf("%d", i); // 6
}




Re: lite-C bug [Re: pascalx] #467856
09/04/17 18:07
09/04/17 18:07
Joined: Feb 2017
Posts: 1,725
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,725
Chicago
Welcome to Lite C!!! grin

In the following example, CASE1 is incorrect and CASE2 is correct syntax.

Code:
//#define CASE1
#define CASE2

int main()
{
	vars b[3];
	var c[3] = { 1.1, 1.2, 1.3 }; vars c1 = c;
	var d[3] = { 2.1, 2.2, 2.3 }; vars d1 = d;
	var e[3] = { 3.1, 3.2, 3.3 }; vars e1 = e;

	b[0] = c1;
	b[1] = d1;
	b[2] = e1;

	d[2] += 10.;
	e1[1] += 20.;

        int i, j;
	for (i = 0; i < 3; i++)
	{
		for (j = 0; j < 3; j++)
		{
                      #ifdef CASE1
                      printf("%.2f ", b[i][j]); //dimension of array error
                      #endif
                      #ifdef CASE2
                      vars f;
                      f = b[i];
                      printf("%.2f ", f[j]); //this works!
                      #endif
		}
		printf("\n");
	}
	return 0;
}


Re: lite-C bug [Re: AndrewAMD] #467858
09/04/17 18:10
09/04/17 18:10
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada
(b[i])[j] also works, if I remember correctly.


Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com
Re: lite-C bug [Re: WretchedSid] #467859
09/04/17 18:18
09/04/17 18:18
Joined: Feb 2017
Posts: 1,725
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,725
Chicago
Originally Posted By: WretchedSid
(b[i])[j] also works, if I remember correctly.

Can confirm CASE3 works. Thanks for the tip!

Code:
//#define CASE1
//#define CASE2
#define CASE3

int main()
{
	vars b[3];
	var c[3] = { 1.1, 1.2, 1.3 }; vars c1 = c;
	var d[3] = { 2.1, 2.2, 2.3 }; vars d1 = d;
	var e[3] = { 3.1, 3.2, 3.3 }; vars e1 = e;

	b[0] = c1;
	b[1] = d1;
	b[2] = e1;

	d[2] += 10.;
	e1[1] += 20.;

        int i, j;
	for (i = 0; i < 3; i++)
	{
		for (j = 0; j < 3; j++)
		{
                      #ifdef CASE1
                      printf("%.2f ", b[i][j]); //dimension of array error
                      #endif
                      #ifdef CASE2
                      vars f;
                      f = b[i];
                      printf("%.2f ", f[j]); //this works!
                      #endif
                      #ifdef CASE3
                      printf("%.2f ", (b[i])[j]);  //this works!
                      #endif
		}
		printf("\n");
	}
	return 0;
}


Re: lite-C bug [Re: AndrewAMD] #467860
09/04/17 18:36
09/04/17 18:36
Joined: Feb 2017
Posts: 1,725
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,725
Chicago
Fixing the opening example, CASE1 is incorrect syntax and CASE2 is correct.

Code:
//#define CASE1
#define CASE2

struct S
{
	int* P;
};

void main()
{
	struct S s;
	s.P = malloc(sizeof(int));
        *(s.P) = 1234; // Ok
        #ifdef CASE1
        s.P[0] = 1234; // Error: subscript requires array or pointer type
        #endif
        #ifdef CASE2
        (s.P)[0] = 1234; // Ok
        #endif
	int* p = s.P;
	p[0] = 2345; // Ok
	printf("%d", *(s.P));
	free(s.P);
}


Re: lite-C bug [Re: AndrewAMD] #467861
09/04/17 18:51
09/04/17 18:51
Joined: Aug 2017
Posts: 58
P
pascalx Offline OP
Junior Member
pascalx  Offline OP
Junior Member
P

Joined: Aug 2017
Posts: 58
Originally Posted By: AndrewAMD
Welcome to Lite C!!! grin


http://www.zorro-trader.com/manual/en/cscript_intro.htm

Quote:
The disadvantage of a script is obviously that you have to learn the script language. Most products using strategy scripts require that you dive deeply into programming. No so with Zorro: lite-C is arguably the world's easiest serious programming language. It 'hides' almost all the programming stuff and allows you to concentrate on plain strategy. You can learn the lite-C essentials in about one day.


I think the emphasis here is on "arguably" grin

I don't understand how offering a limited subset of features is better than offering the whole package.
I rather take the whole thing even if I don't need all of it.
But it's ok. The upcoming Zorro DLL will solve a lot of headache.

Last edited by pascalx; 09/04/17 18:55.
Re: lite-C bug [Re: pascalx] #467863
09/04/17 19:33
09/04/17 19:33
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada
Because a broken subset of C is much easier to implement as a compiler. Why not use a LLVM/Clang as a compiler backend? Because they didn't exist back in 1423 when Lite-C was invented. But really, it's because with LLVM/Clang we would have never had the drama of the Chinese freelancer that bailed halfway through implementing the compiler leaving JCL with a bunch of Chinese comments and a voodoo black magic compiler.


Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com
Re: lite-C bug [Re: WretchedSid] #467864
09/04/17 19:57
09/04/17 19:57
Joined: Aug 2017
Posts: 58
P
pascalx Offline OP
Junior Member
pascalx  Offline OP
Junior Member
P

Joined: Aug 2017
Posts: 58
Originally Posted By: WretchedSid
1423



Re: lite-C bug [Re: pascalx] #468175
09/22/17 11:35
09/22/17 11:35
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
Code:
int *_ap = &1;
*_ap += 1;
error ( str_for_int ( NULL, 1 ) ); // Prints 2


Re: lite-C bug [Re: txesmi] #468745
10/15/17 13:20
10/15/17 13:20
Joined: Aug 2017
Posts: 58
P
pascalx Offline OP
Junior Member
pascalx  Offline OP
Junior Member
P

Joined: Aug 2017
Posts: 58
Wait - every one is a two then? Hahaha.

Re: lite-C bug [Re: pascalx] #468746
10/15/17 15:35
10/15/17 15:35
Joined: Oct 2011
Posts: 1,082
Germany
C
Ch40zzC0d3r Offline
Serious User
Ch40zzC0d3r  Offline
Serious User
C

Joined: Oct 2011
Posts: 1,082
Germany
They probably have all constants in the data section, therefore this is possible on this compiler lol.
Take a look at the generated assembly.

Last edited by Ch40zzC0d3r; 10/15/17 15:36.
Re: lite-C bug [Re: Ch40zzC0d3r] #468747
10/15/17 16:00
10/15/17 16:00
Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
MasterQ32 Offline
Expert
MasterQ32  Offline
Expert

Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
you can also write any statements outside of function definitions:

Code:
#include <acknex.h>

int i, j, k;
i = 10;
j = 20;
k = i + j;

printf("i=%d", i);

function main()
{

}



Nothing will happen, the compiler won't even emit a warning

Fun Fact:
You can implement generic functions with the behaviour that you can take the address of a constant:

Code:
void _list_add(void * list, void * obj, int size);

#define list_add(list, obj) _list_add(list, &obj, sizeof(obj))

...

list_add(myList, 10);
list_add(myList, 20);



Visit my site: www.masterq32.de
Page 1 of 2 1 2

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