<br><br><div class="gmail_quote">2009/10/16 srs <span dir="ltr"><<a href="mailto:skaflotten@gmail.com">skaflotten@gmail.com</a>></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Daniel Waterworth skrev:<div class="im"><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Thanks very much. I only have one more question, (hopefully), which is, is there a better way of finding the direction of stack growth other than:<br>
<br>
static bool StackCmp(void *ptr) {<br>
volatile int a;<br>
return (void *)&a > ptr;<br>
}<br>
<br>
bool FindStackDirection() {<br>
volatile int a;<br>
return StackCmp((void *)&a);<br>
}<br>
<br>
Preferably one which isn't destroyed by optimization.<br>
</blockquote>
<br></div>
I suggest you turn the scalars into arrays and make the ptr argument volatile as well.<br>
<br>
Other ways: If you are careful with tail recursion eliminiation, you can compare local var addresses from different recursive calls. I believe there are va_arg based approaches as well.<br>
<br>
That said, there is no truly portable way.<br>
<br>
/Stein Roger<br></blockquote><div><br>I've changed the ptr argument to volatile and the StackCmp function to noinline. It's now providing the correct answer in gcc and llvm-gcc with optimization on -O3. This will suite my puposes, at least for the time being.<br>
<br>Thanks alot,<br><br>Daniel<br></div></div><br>