Nadodiyin Pulambal

A Wanderer Gripes

Archive for March, 2007

Posted by kovaiputhalvan on March 12, 2007

Hmmm.

So there *are* processors on which the stack grows upwards. I’d always heard of these beasts, but till I read that post, they were pretty much unicorns to me. This at once shows off my youth and ignorance.

Came across this nice little puzzle late last week, which set me thinking about stacks and how they grow:


Drat. Somehow, I’m not able to get this thing to display C code properly. Anyway, the code is fairly simple – you have an int i, an int a[10], and then you have a for loop with i as the loop counter, writing past the end of array a.
What happens is that you overwrite the value of the loop counter, and you end up in an infinite loop. *If* you’re running it on a machine that has stacks growing downwards, that is. Okay, on a machine that has arrays and stacks growing in opposite directions.

Aw shucks. It’s nearing the end of lunchtime and I need to get back to work. I’ll be back to edit this post later. Don’t know when, though.

Posted in Not Worth Reading, stuff | Leave a Comment »