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
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 1,014 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 5 of 5 1 2 3 4 5
Re: A8 Version 8.012 Public Beta [Re: Lukas] #333342
07/15/10 20:44
07/15/10 20:44
Joined: Sep 2003
Posts: 929
Spirit Offline

Moderator
Spirit  Offline

Moderator

Joined: Sep 2003
Posts: 929
No there is no array of pointers. This would really be a waste of memory. The compiler translates your two indexes to an expression like in the example from JustSid.

array[row][col] => array[(row * n) + col]


Re: A8 Version 8.012 Public Beta [Re: Spirit] #333345
07/15/10 20:48
07/15/10 20:48
Joined: May 2007
Posts: 2,043
Germany
Lukas Offline

Programmer
Lukas  Offline

Programmer

Joined: May 2007
Posts: 2,043
Germany
Oh, ok, that makes sense. And then there is really a hige difference between arrays and pointers. But that somehow makes me really wonder why I can use pointers to pointers as function parameters to pass a 2-dimensional array. confused
And this also means that there is really no way to create a native array that can be used with [x][y] brackets. shocked

Re: A8 Version 8.012 Public Beta [Re: Lukas] #333361
07/15/10 21:58
07/15/10 21:58
Joined: Mar 2002
Posts: 1,774
Magdeburg
F
FlorianP Offline
Serious User
FlorianP  Offline
Serious User
F

Joined: Mar 2002
Posts: 1,774
Magdeburg
As the memory itself is pretty much a one-diemensional array (as it has one index) there is of course no way to create a 'native' two-diemensional array. The CPU only knows adresses in the memory and doenst care about higher data-structures - its the compilers task to make sure that the resulting assembler-code adresses the memory like the programmer intented. So the only reason for these sturctures to exist is indeed their convenience for programmer in higher-languages.

The pointer (aka indirect adressing-modes) on the other hand is one of the most native concepts of a CPU. The compiled assembler-code uses it for nearly every memory- or function-call made by a higher language.
And a pointer only directs to annother memore-location - and if that location directs to the next, and to the next...and so on - you can also use '******' (and the compiled code maybe really does [see Binding]) to direct to an two-diemensional array. The pointers just lead you the way - whats on the end of it doesnt matter.

Last edited by FlorianP; 07/15/10 22:06.

I <3 LINQ
Re: A8 Version 8.012 Public Beta [Re: FlorianP] #333368
07/15/10 22:29
07/15/10 22:29
Joined: May 2007
Posts: 2,043
Germany
Lukas Offline

Programmer
Lukas  Offline

Programmer

Joined: May 2007
Posts: 2,043
Germany
By "native" I meant a fixed size array like int myarray[3][5], in comparision to an array created by malloc. I know how the CPU and the memory works. What I meant, when I said, you can't create native arrays on runtime, was that you can't create arrays that work like if you defined them like int myarray[3][5].

My point about the **-pointer is that I thought this works:
Code:
int myarray[3][5];
void dosomething(int **array)
{
	(array[2])[3] = 3;
}


But now I tried it and it doesn't work. I always thought it would work, because it does work for 1-dimensional arraye. That's why I was confused when I heard that there is a huge difference between **-pointers and 2-dimensional arrays.
But now that I found out that this doesn't work, everything sounds logical again. laugh

Good that I learned that.


But then, Lite-C should support arrays with indefinite size (or arrays at all...) in function parameters, like this:
void myfunction (int myarray[])

Re: A8 Version 8.012 Public Beta [Re: Lukas] #333371
07/15/10 22:57
07/15/10 22:57
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada
Code:
int test[1][1];

void foo(int **bar)
{
	(bar[0])[0] = 1;	
}

...

foo(test);



This works pretty good inside the VM


Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com
Re: A8 Version 8.012 Public Beta [Re: WretchedSid] #333373
07/15/10 23:01
07/15/10 23:01
Joined: May 2007
Posts: 2,043
Germany
Lukas Offline

Programmer
Lukas  Offline

Programmer

Joined: May 2007
Posts: 2,043
Germany
Yeah but it crashes. (Maybe not for you now, because you use [0][0]...)

Re: A8 Version 8.012 Public Beta [Re: Lukas] #333374
07/15/10 23:02
07/15/10 23:02
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada
Uhm... possible, but I don't want't to start the VM again to check it out tongue


Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com
Re: A8 Version 8.012 Public Beta [Re: WretchedSid] #333376
07/15/10 23:10
07/15/10 23:10
Joined: Jul 2009
Posts: 1,198
Berlin, Germany
L
Liamissimo Offline
Serious User
Liamissimo  Offline
Serious User
L

Joined: Jul 2009
Posts: 1,198
Berlin, Germany
This thread now have 3 sites about a theme I understand in no way grin


"Ich weiss nicht genau, was Sie vorhaben, aber Sie können keine Triggerzonen durch Ihr Level kullern lassen."
-JCL, 2011
Re: A8 Version 8.012 Public Beta [Re: Liamissimo] #333437
07/16/10 13:40
07/16/10 13:40
Joined: Jan 2003
Posts: 4,615
Cambridge
Joey Offline
Expert
Joey  Offline
Expert

Joined: Jan 2003
Posts: 4,615
Cambridge
In C you are able to pass multidimensional arrays as pointers. Although the compiler does not know the length of the array itself (char a[2] stores no length) it does need to know the length of the rows in order to make the replacement spirit mentioned in his post. So how do we declare such a function? In C, it is

Code:
void foo(int array[][20]);
// or equivalently (pointer and array are more or less the same data type in C)
void foo(int (*array)[20]);


the following code is wrong since it receives a pointer to an array, not a pointer to a pointer:

Code:
void foo(int **array);



Re: A8 Version 8.012 Public Beta [Re: Joey] #333618
07/17/10 18:25
07/17/10 18:25
Joined: Apr 2008
Posts: 650
Sajeth Offline
User
Sajeth  Offline
User

Joined: Apr 2008
Posts: 650
How do I upgrade my A7 commercial license?


Teleschrott-Fan.
Page 5 of 5 1 2 3 4 5

Moderated by  Matt_Coles 

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