Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
1 registered members (TipmyPip), 18,449 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 3 1 2 3
Re: Script Crash [Re: Uhrwerk] #411527
11/17/12 15:11
11/17/12 15:11
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
It sure does support indirection mutliple times:
Code:
#include <acknex.h>

int i = 0;

void main()
{
	int* p1 = &i;
	int** p2 = &p1;
	(*(*p2)) = 1337;
	printf("%d",i);
}



Always learn from history, to be sure you make the same mistakes again...
Re: Script Crash [Re: Uhrwerk] #411530
11/17/12 15:14
11/17/12 15:14
Joined: Nov 2011
Posts: 139
India
Yashas Offline OP
Member
Yashas  Offline OP
Member

Joined: Nov 2011
Posts: 139
India
Sorry! I deleted the post, becaz when I went to try a multiple indirection, I never gave a address of a pointer instead a variable, hence I encountered an error.

Sorry! laugh


Keep smiling laugh
http://translation.babylon.com/ - Translate many languages
Re: Script Crash [Re: Uhrwerk] #411534
11/17/12 15:22
11/17/12 15:22
Joined: Nov 2011
Posts: 139
India
Yashas Offline OP
Member
Yashas  Offline OP
Member

Joined: Nov 2011
Posts: 139
India
Originally Posted By: Uhrwerk
Code:
SpeedRun_Time = 60;


That is wrong. SpeedRun_Time is a pointer. You write the address 60 to that pointer. What you intended to do was setting the integer value SpeedRun_Time was pointing to, right?


Exactly, so I shud *SpeedRun_Time = 60; right??

And thats really not funny of the compiler ( tongue ) to show crash in so and so but it isn't the crash there(Many might not be knowing :D) and it's the line preceding the function call. tongue


Keep smiling laugh
http://translation.babylon.com/ - Translate many languages
Re: Script Crash [Re: Yashas] #411536
11/17/12 15:24
11/17/12 15:24
Joined: Nov 2011
Posts: 139
India
Yashas Offline OP
Member
Yashas  Offline OP
Member

Joined: Nov 2011
Posts: 139
India
*SpeedRun_Time = 60; did not work!
My C book shows to add a * before assigning a value to the variable pointed by the pointer but whats wrong here??


Keep smiling laugh
http://translation.babylon.com/ - Translate many languages
Re: Script Crash [Re: Yashas] #411537
11/17/12 15:25
11/17/12 15:25
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada
Have you initialized your pointer?


Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com
Re: Script Crash [Re: Yashas] #411538
11/17/12 15:28
11/17/12 15:28
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
The compiler has already done all of its work at that time, so you can't blame him. tongue

In general: There might be scenarios where writing an address to pointer is valid. The most basic usage of this is "MyPointer = NULL". That is basically the same. This is one of the unlucky cases where you encounter errors previously done much later - or never at all.

EDIT: @JustSid: He did.


Always learn from history, to be sure you make the same mistakes again...
Re: Script Crash [Re: Uhrwerk] #411548
11/17/12 16:01
11/17/12 16:01
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada
Oh god, I totally ignored the first post. Ashes on my head.


Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com
Re: Script Crash [Re: WretchedSid] #411550
11/17/12 16:06
11/17/12 16:06
Joined: Nov 2011
Posts: 139
India
Yashas Offline OP
Member
Yashas  Offline OP
Member

Joined: Nov 2011
Posts: 139
India
@JustSid LOL

And now how do I change the value of the variable pointed by a pointer??
All C books show " *variable = value;" but that dint work.


Keep smiling laugh
http://translation.babylon.com/ - Translate many languages
Re: Script Crash [Re: Yashas] #411554
11/17/12 16:33
11/17/12 16:33
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline
Expert
Kartoffel  Offline
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Originally Posted By: Yashas
All C books show " *variable = value;" but that dint work.
it should work:
Code:
#include <acknex.h>

void main()
{
	int * int_ptr_to_mem = sys_malloc(sizeof(int));
	*int_ptr_to_mem = 1234; //  >> *variable = value; <<
	
	int output = *int_ptr_to_mem; // printf doesn't work with pointers as value
	printf("int_ptr_to_mem = %.0f", (double)output);
}

...works fine for me confused


POTATO-MAN saves the day! - Random
Re: Script Crash [Re: Kartoffel] #411556
11/17/12 17:15
11/17/12 17:15
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
You can of course diretly use printf.
Code:
#include <acknex.h>

void main()
{
	int * int_ptr_to_mem = sys_malloc(sizeof(int));
	
	*int_ptr_to_mem = 1234; //  >> *variable = value; <<
	printf("int_ptr_to_mem = %d",*int_ptr_to_mem);
	printf("address of int_ptr_to_mem = %p",int_ptr_to_mem);
	
	ptr_remove(int_ptr_to_mem);
}


Last edited by Uhrwerk; 11/17/12 17:18. Reason: of course vs. of cause. *grrrrr*

Always learn from history, to be sure you make the same mistakes again...
Page 2 of 3 1 2 3

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

Gamestudio download | 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