View previous topic :: View next topic |
Author |
Message |
kot1990 Expert Cheater
Reputation: 1
Joined: 06 Sep 2009 Posts: 131 Location: Greece
|
Posted: Thu Nov 19, 2009 7:17 pm Post subject: Strange pointer way! |
|
|
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 . Anyone have any clues for what it may be?
|
|
Back to top |
|
 |
iPromise Grandmaster Cheater
Reputation: -1
Joined: 27 Jun 2009 Posts: 529 Location: Canada
|
Posted: Thu Nov 19, 2009 7:22 pm Post subject: |
|
|
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 |
|
 |
kot1990 Expert Cheater
Reputation: 1
Joined: 06 Sep 2009 Posts: 131 Location: Greece
|
Posted: Thu Nov 19, 2009 7:27 pm Post subject: |
|
|
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 |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Thu Nov 19, 2009 8:16 pm Post subject: |
|
|
it's just a reference. i am glad you find it so whimsical and amazing though.
|
|
Back to top |
|
 |
Flyte Peanuts!!!!
Reputation: 6
Joined: 19 Apr 2006 Posts: 1887 Location: Canada
|
|
Back to top |
|
 |
tombana Master Cheater
Reputation: 2
Joined: 14 Jun 2007 Posts: 456 Location: The Netherlands
|
Posted: Fri Nov 20, 2009 4:36 am Post subject: |
|
|
@Athaem
Why is it better to use references than pointers?
(I myself use them mixed)
|
|
Back to top |
|
 |
Flyte Peanuts!!!!
Reputation: 6
Joined: 19 Apr 2006 Posts: 1887 Location: Canada
|
Posted: Fri Nov 20, 2009 1:51 pm Post subject: |
|
|
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 |
|
 |
Dark Byte Site Admin
Reputation: 470
Joined: 09 May 2003 Posts: 25792 Location: The netherlands
|
Posted: Fri Nov 20, 2009 2:16 pm Post subject: |
|
|
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 |
|
 |
kot1990 Expert Cheater
Reputation: 1
Joined: 06 Sep 2009 Posts: 131 Location: Greece
|
Posted: Sat Nov 21, 2009 8:02 pm Post subject: |
|
|
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 . 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 |
|
 |
|