Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Strange pointer way!

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
kot1990
Expert Cheater
Reputation: 1

Joined: 06 Sep 2009
Posts: 131
Location: Greece

PostPosted: Thu Nov 19, 2009 7:17 pm    Post subject: Strange pointer way! Reply with quote

I found on some site a strange way to declare a pointer. It goes like this.

Code:
double num = 50;
double &numPoint = num;


if you don't put the "= num" it won't work!
As I understand it seems that it gets the address of num and saving to numPoint, but if you print numPoint it will automatically dereference to the num variable and show 50. If you print &numPoint it will show the address of the num again. It seems like a hidden pointer and it works for all data types! I see a good in this, that you don't need to put any preceding operators before the numPoint, it accesses towards the value of num Smile. Anyone have any clues for what it may be?
Back to top
View user's profile Send private message
iPromise
Grandmaster Cheater
Reputation: -1

Joined: 27 Jun 2009
Posts: 529
Location: Canada

PostPosted: Thu Nov 19, 2009 7:22 pm    Post subject: Reply with quote

Okay from reading this code I can see you posting a small amount of the full code.

I'm guessing NumPoint is the pointer, and what they are TRYING to do is to use DMA (DirectMemoryAccess) to edit the pointer, but that clearly fails.
Back to top
View user's profile Send private message MSN Messenger
kot1990
Expert Cheater
Reputation: 1

Joined: 06 Sep 2009
Posts: 131
Location: Greece

PostPosted: Thu Nov 19, 2009 7:27 pm    Post subject: Reply with quote

iPromise wrote:

I'm guessing NumPoint is the pointer, and what they are TRYING to do is to use DMA (DirectMemoryAccess) to edit the pointer, but that clearly fails.


You are just guessing, I tried it and it works man, I am not asking if it works
Back to top
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Thu Nov 19, 2009 8:16 pm    Post subject: Reply with quote

it's just a reference. i am glad you find it so whimsical and amazing though.
Back to top
View user's profile Send private message
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Thu Nov 19, 2009 10:33 pm    Post subject: Reply with quote

It is a reference, and it's what you should be using instead of pointers whenever you can.

In fact, I just finished telling you so here: http://forum.cheatengine.org/viewtopic.php?t=472459
Back to top
View user's profile Send private message
tombana
Master Cheater
Reputation: 2

Joined: 14 Jun 2007
Posts: 456
Location: The Netherlands

PostPosted: Fri Nov 20, 2009 4:36 am    Post subject: Reply with quote

@Athaem
Why is it better to use references than pointers?
(I myself use them mixed)
Back to top
View user's profile Send private message
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Fri Nov 20, 2009 1:51 pm    Post subject: Reply with quote

tombana wrote:
@Athaem
Why is it better to use references than pointers?
(I myself use them mixed)


In almost every instance, a reference is guaranteed to be valid.

There are only two instances where it could possibly be invalid; one is the result of assigning your reference to a dereferenced null pointer, and the other is returning by reference a local value on the stack.
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 470

Joined: 09 May 2003
Posts: 25792
Location: The netherlands

PostPosted: Fri Nov 20, 2009 2:16 pm    Post subject: Reply with quote

If i'm correct another pro of this is that numpoint itself does not use up any stackspace to store the address of num

so while :
Code:

double num = 50;
double *numPoint = #

would take up 12 bytes on the stack

while
Code:

double num = 50;
double &numpoint=num;

will only take up 8 bytes on the stack


------
pascal
------
pascal has a similar method:
Code:

var
  num: double;
  numpoint: double absolute num;

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
kot1990
Expert Cheater
Reputation: 1

Joined: 06 Sep 2009
Posts: 131
Location: Greece

PostPosted: Sat Nov 21, 2009 8:02 pm    Post subject: Reply with quote

Wow, dark byte you satisfy me, I didn't expect that kind of answer from anyone. Again I learned something new. Actually I want to learn assembly and how the compiler translates all that stuff writen in high level languages to asm, but all the stuff I find to read is all very general and boring. I need something with specific examples to learn and all these details like the one I posted to be explained with a simple way. You know to have fun a little bit Very Happy. I know you can make funny stuff with asm, and be the best programmer, but its hard to find a good document to read. If you could post a link please?
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites