Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
@Lensflare in low-level areas where a stack really matteres, a stack overflow is not fantasy.
-
@IntrusionCM not a problem for the implementations of stack that I have ever worked with. It just does the empty check automatically.
-
@Lensflare I meant underflow in that comment
The stack is usually just a block of memory with an integer pointer acting as a bookmark. Popping the stack just decrements the pointer. So if you decrement the pointer past zero it will underflow.
Popping an empty stack can be problematic especially in lower level implementations -
Yeah I agree.
What I meant was seeng an actual stack underflow. Like the exceptions that you get in higher languages like Java and C# when an overflow happens. The exceptions also have the name "overflow" in them.
In the case of stack overflows, the name "overflow" can be found in the printed stack trace as well.
The same higher languages will probably make all kind of checks to prevent a stack underflow from happening directly in the data structure. So, we won’t see them.
In lower languages like C++ they can happen but I guess you’ll never see the actual name "underflow". Because it will be just a crash or it will manifest in data corruption or bugs. -
@Lensflare in C# it results in an InvalidOperationException
Java has its own specific EmptyStackException
Popping an empty array in JS just returns undefined
C++ just segfaults -
@IntrusionCM
Swift’s standard data types is my favorite:
It does nothing and returns nil instead of the value at the top.
Similar to JS, I suppose. -
@Lensflare I wouldn't take JS as an example reference, cause we all know JS is bonkers.
But yes, the implementation needs to either not validate properly or (e.g. in the wonderful world of asynchronous / simultaneous access) an lock or similar protection is missing / erroneously implemented.
@PonySlaystation I'm too dumb for shit like that. Should the smart kids play with their spins, quarks and whatever else they toy with. -
@PonySlaystation lalalalala *emotional support system encountered an stack underflow, no resources available for consumption*
-
@IntrusionCM JS has to do *something* right, if just by chance. But most of the time when it looks right, on a closer look, it’s fundamentally broken or a workaround on a workaround.
-
@Lensflare you just described what it does right. Easy on the surface, clusterfuck exponentially beneath.
I hate that "integer overflows" have become somewhat pop culture because anytime I see someone try to use it in a joke, they use it wrong.
I've even seen people confuse them with stack overflows and be like "my intelligence is so low it stack underflowed and became the max of an integer value!"
Or "It overflowed and became zero again" ah, I guess it happened to be unsigned and overflowed by precisely 1 then eh?
So cringe
rant