Gamestudio Links
Zorro Links
Newest Posts
Zorro version 3.0 prerelease!
by TipmyPip. 02/25/26 16:38
ZorroGPT
by TipmyPip. 02/25/26 12:15
WFO Training with parallel cores Zorro64
by Martin_HH. 02/24/26 19:51
Camera always moves upwards?
by clonman. 02/21/26 09:29
Sam Foster Sound | Experienced Game Composer for Hire
by titanicpiano14. 02/19/26 13:22
AUM Magazine
Latest Screens
Dorifto samurai
Shadow 2
Rocker`s Revenge
Stug 3 Stormartillery
Who's Online Now
5 registered members (TipmyPip, Grant, AndrewAMD, alibaba, Martin_HH), 5,525 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
alx, ApprenticeInMuc, PatrickH90, USER0328, Sfrdragon
19199 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Pointer bounds checking #282073
07/30/09 08:46
07/30/09 08:46
Joined: Dec 2008
Posts: 271
Saturnus Offline OP
Member
Saturnus  Offline OP
Member

Joined: Dec 2008
Posts: 271
Hello,

I have an array allocated at runtime and I would like to check, if a pointer points to a location in memory that belongs to that array.

Does somebody know how/if I can do that in lite-C?

Thanks

Re: Pointer bounds checking [Re: Saturnus] #282079
07/30/09 09:30
07/30/09 09:30
Joined: Oct 2007
Posts: 5,211
İstanbul, Turkey
Quad Offline
Senior Expert
Quad  Offline
Senior Expert

Joined: Oct 2007
Posts: 5,211
İstanbul, Turkey
yes you can skim thru the array in loop and chck all elements one by one, check if they're same with your pointer


3333333333
Re: Pointer bounds checking [solved] [Re: Quad] #282093
07/30/09 11:02
07/30/09 11:02
Joined: Dec 2008
Posts: 271
Saturnus Offline OP
Member
Saturnus  Offline OP
Member

Joined: Dec 2008
Posts: 271
Thank you, Quadraxas.
Yes, this was possible. However, I was wondering if there was a more efficient way to do this.

And indeed there is by just comparing the pointers. It's an obvious thing actually. : )

Code:
int *arr = malloc(sizeof(int) * 100);
int *ptr = &arr[50];

if ((ptr >= &arr[0]) && (ptr <= &arr[99]))
	printf("within bounds");
else
	printf("out of bounds");




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