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
3 registered members (Ayumi, NewbieZorro, TipmyPip), 13,887 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
operating pointers #449304
03/13/15 09:24
03/13/15 09:24
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline OP
Serious User
txesmi  Offline OP
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
Hi all,
I needed to know the members count between two of an array. I thought on substract their addresses and divide by their lenght in order to avoid an index management.

Code:
int count = ( (unsigned long)nodeEndPtr - (unsigned long)nodeStartPtr ) / sizeof(NODE**);



As far as I test it, it works but is it feasible/secure?
Salud!

Last edited by txesmi; 03/13/15 09:39.
Re: operating pointers [Re: txesmi] #449305
03/13/15 09:50
03/13/15 09:50
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada
If it is a continuous block of memory, why wouldn't it?


Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com
Re: operating pointers [Re: WretchedSid] #449306
03/13/15 10:25
03/13/15 10:25
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline OP
Serious User
txesmi  Offline OP
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
My doubts grow when I do this test

Code:
unsigned long l = (1<<31);
error ( str_for_int ( NULL, l ) );
printf ( "% d", l );



and I can read -2147... in both cases.

I'd hope that the problem comes from the transformation to a string but I can't be sure. I had some troubles with unsigned in the past. Can I trust that the compiler does the work as it is spected?

Thanks for your time!

Last edited by txesmi; 03/13/15 10:34.
Re: operating pointers [Re: txesmi] #449309
03/13/15 11:35
03/13/15 11:35
Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
MasterQ32 Offline
Expert
MasterQ32  Offline
Expert

Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
Lite-C silently ignores "unsigned". You just can't have signed types.


Visit my site: www.masterq32.de
Re: operating pointers [Re: txesmi] #449310
03/13/15 11:37
03/13/15 11:37
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada
unsigned and signed are not different on a bit level, either one can be interpreted as the other. It counts what you tell the compiler, in this case, you pass it to str_for_int(), which expected a signed integer. The compiler will just pass your unsigned integer and the function will treat is as signed. Same with %d, which is the format specifier for a signed integer.

Of course, for the least significant bit to be affected in the first place, you'd have to subtract two pointers that are both at either end of the heap, and I have my doubts that you have such a continuous block of memory anywhere.


Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com
Re: operating pointers [Re: WretchedSid] #449314
03/13/15 13:20
03/13/15 13:20
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline OP
Serious User
txesmi  Offline OP
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
@MasterQ32
That had in mind.

@GenuineSid
Ok, I needed to check the bits of a negative integer to realize that I was terribly wrong with its content. Now I understand the sign called bit is the result of the bit collapse and is not a reference flag as happens in maths. It is the same operation on signed and unsigned. Loose knot.

The other point touches another doubt I had: what a pointer describes exactly. Is it a global address? or an offset into some sort of application memory block? From your sentence, it seems those blocks do exists.

Sincerely grateful.

Re: operating pointers [Re: txesmi] #449316
03/13/15 15:46
03/13/15 15:46
Joined: Oct 2011
Posts: 1,082
Germany
C
Ch40zzC0d3r Offline
Serious User
Ch40zzC0d3r  Offline
Serious User
C

Joined: Oct 2011
Posts: 1,082
Germany
Originally Posted By: txesmi
@MasterQ32
That had in mind.

@GenuineSid
Ok, I needed to check the bits of a negative integer to realize that I was terribly wrong with its content. Now I understand the sign called bit is the result of the bit collapse and is not a reference flag as happens in maths. It is the same operation on signed and unsigned. Loose knot.

The other point touches another doubt I had: what a pointer describes exactly. Is it a global address? or an offset into some sort of application memory block? From your sentence, it seems those blocks do exists.

Sincerely grateful.


A pointer is an address within your process space.
Extern programs can access your process by using some windows APIs like ReadProcessMemory.
All that stuff is managed by the kernel and in most cases you only want the virtual memory addresses. But you can also get the physical memory addresses and modify them with a kerneldriver.
Take a look at Cheat Engine and OllyDbg to learn more about the pointers and their relation to assembler

Last edited by Ch40zzC0d3r; 03/13/15 15:49.
Re: operating pointers [Re: txesmi] #449324
03/14/15 17:41
03/14/15 17:41
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada
Originally Posted By: txesmi
The other point touches another doubt I had: what a pointer describes exactly. Is it a global address? or an offset into some sort of application memory block? From your sentence, it seems those blocks do exists.


Chaoscoder didn't really give you an either correct nor satisfying answer (imho), so let me try to give it a shot, thanks to some historic decisions it is a tad complicated.

For all intents and purposes, a pointer is a global address, which also happens to be an offset. The null pointer points 0 bytes into the RAM, a pointer with the value 0x1000 points 4096 bytes into the RAM. The important thing is that the smallest addressable unit is one byte, so a pointer with value 0x1 points to the second byte in memory.

Now, it would be huge security issue if every program would be in the same address space, as every program could read and write over other program memory. Historically, in DOS times, this used to be the case. But even without security concerns, one wrong pointer could take down the whole system. So, modern CPUs and operating systems have virtual address spaces. For your program it looks like its got a whole 4gb address space that it doesn't share with anyone else. A small hardware unit called MMU (memory management unit) translates your virtual address space pointers into physical addresses and does the RAM access. The operating system is in charge of handling all virtual address spaces and providing physical memory backing for memory pages.

This has some huge advantages. Security on one hand, but, shared libraries for example can be loaded once into memory and be mapped read only into all the programs virtual address spaces that uses it. The system allows for arbitrary mappings between virtual and physical pages, and that on a per virtual address space basis. And it's all transparent to your program, it never has to know what physical address your pointer resolves to, for you it just looks like one large continous address space.

Now, since we are talking about x86 here: Technically there is one more thing that can affect what a pointer resolves to: The segment registers. Intel thought it was a great idea back in a long time ago to allow for segmentation of memory. This was kind of like poor mans virtual address spaces, before they came about. Segmentation is tricky, and unnecessary, because all modern operating systems have one segment for the whole address space and call it a day (in which case there is no extra pointer translation).

The major thing to take away though is that pointers really are just 32bit integers! They hold integer values which represent addresses into memory. Wether you call it an offset or not is your thing, the analogy would be street numbers. Is house number 38 the 38th house from the beginning of the street, or is "Foo Street 38" an absolute address?


Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com
Re: operating pointers [Re: WretchedSid] #449328
03/15/15 08:56
03/15/15 08:56
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline OP
Serious User
txesmi  Offline OP
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
Thank you very much! It is really appreciated. Many indexes in my code files will dissapear by the way laugh


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