PDA

View Full Version : How to check if Stack is empty


xar
03-01-04, 12:55 PM
Hi,
is there a way to know how many entries are in the stack?

I started to design a routine that waits for a SPI device response, and I wanted to return the value if it could be grabbed within a timeout. If there is no answer, it should not add anything to the stack.

Now I need a way to test if there is something in the stack, and I came with this:


255
SDANSWER
255 = IF
." Timeout!" CR
THEN

255 can't be returned by SDASWER, so it is clearly a timeout, since it didn't return anything.

Now I have to empty the stack anyway after use, so the problem is the same.
How do I check how many elements are into the stack?

TIA,

Giuseppe Marullo

RMDumse
03-01-04, 01:05 PM
I think the word DEPTH is what you want. DEPTH returns the number of items that were on the stack (before you asked the question which added one more!)

xar
03-01-04, 01:16 PM
Randy,
thanks for the answer. Please do check the email in the next few minutes...I have news for you.