On Fri, 3 Feb 2012, Juan Jose Garcia-Ripoll wrote: > I just noticed that some cleverly optimizing compilers broke the code I used > to detect whether the stack grows upwards or downwards. I will upload a patch > tonight.
Wouldn't two calls to alloca() in a single function give a reliable answer on pretty much all platforms? #include <alloca.h> #include <stdio.h> int main() { void *x; void *y; x=alloca(100); y=alloca(100); printf("delta: %d\n", (int)(y-x)); return 0; } The following was another idea; but it looks no better than what you have now. #include <stdio.h> #include <stdlib.h> void * start; void * end; void recurse(int n, void *y) { int x; if(n==0) end=&x; else recurse(n-1, &x); } int main(int argc, char **argv) { int x; int times; start=&x; times=(random()%10)+1; recurse(times, start); printf("delta: %d\n", (int)(end-start)); return 0; } This link indicates Sparc could violate some common assumptions about stack behavior (though it looks to me like he was confusing the register window with the stack). http://stackoverflow.com/questions/664744/what-is-the-direction-of-stack-growth-in-most-modern-systems - Daniel ------------------------------------------------------------------------------ Virtualization & Cloud Management Using Capacity Planning Cloud computing makes use of virtualization - but cloud computing also focuses on allowing computing to be delivered as a service. http://www.accelacomm.com/jaw/sfnl/114/51521223/ _______________________________________________ Ecls-list mailing list Ecls-list@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/ecls-list