Discuss the development of new homebrew software, tools and libraries.
Moderators: cheriff , TyRaNiD
sg57
Posts: 144 Joined: Fri Oct 14, 2005 2:26 pm
Post
by sg57 » Tue Aug 08, 2006 8:07 am
I'm just curious, since we can point to pointers, how many levels of this re-direction can the compilier take before it runs out of stack space? Here is an example...
Code: Select all
int i = 3;
int* pi = &i;
int** p2i = π
int*** p3i = &p2i;
int**** p4i = &p3i;
int***** p5i = &p4i;
int****** p6i = &p5i;
int******* p7i = &p6i;
int******** p8i = &p7i;
int********* p9i = &p8i;
int********** p10i = &p9i;
int*********** p11i = &p10i;
int************ p12i = &p11i;
int************* p13i = &p12i;
int************** p14i = &p13i;
int*************** p15i = &p14i;
int**************** p16i = &p15i;
int***************** p17i = &p16i;
int****************** p18i = &p17i;
int******************* p19i = &p18i;
int******************** p20i = &p19i;
int********************* p21i = &p20i;
int********************** p22i = &p21i;
int*********************** p23i = &p22i;
int************************ p24i = &p23i;
int************************* p25i = &p24i;
int************************** p26i = &p25i;
int*************************** p27i = &p26i;
int**************************** p28i = &p27i;
int***************************** p29i = &p28i;
int****************************** p30i = &p29i;
int******************************* p31i = &p30i;
int******************************** p32i = &p31i;
int********************************* p33i = &p32i;
I'm sure it would slow down any application using such a mass amount of re-direction if it did compile... So could i get an estimate? 3,000?
Last edited by
sg57 on Tue Aug 08, 2006 8:13 am, edited 1 time in total.
groepaz
Posts: 305 Joined: Thu Sep 01, 2005 7:44 am
Contact:
Post
by groepaz » Tue Aug 08, 2006 8:12 am
i would think that its hard to give a general answer to this, it would heavily depend on how those pointers are actually used :)
but it could be an interisting experience to both write and later read some code that uses such stuff in a non trivial way :)
sg57
Posts: 144 Joined: Fri Oct 14, 2005 2:26 pm
Post
by sg57 » Tue Aug 08, 2006 8:15 am
I dont really see an easy way, unless you, by hand, type it all up to 3,000 or however many...
Unless you make an array of pointers, all pointing to the element below them... In theory...
jimparis
Posts: 1145 Joined: Fri Jun 10, 2005 4:21 am
Location: Boston
Post
by jimparis » Tue Aug 08, 2006 8:22 am
Dereferencing pointers has nothing to do with the stack. You could dereference pointers all day if you felt like it. The only issue is that you actually need to store the pointers somewhere, so the limit would be the amount of RAM you have available.