RE: [C] Type Ambiguous Stack 01-03-2015, 06:26 PM
#6
(01-03-2015, 05:48 PM)phyrrus9 Wrote: That is a way to do a "template" stack in C, but not a real stack. Since you are only able to put integers on that stack.
How is it not a real stack because it's limited to a single type? The templated std:
tack type in C++ only supports a single type unless you create a container to wrap around embedded data of certain types to add to the stack so that it's recognized as a single type. The idea of a stack is typically LIFO, as to what goes on the pile, it doesn't matter. The only way yours works with multiple types above is because you're using void pointers, and because it's a pointer all of the same type, and not the actual data being added to some kind of stack container, you don't have to deal with padding and memory alignment issues, but you're still going to have to cast back to the original type in question.




![[+]](https://sinister.li/images/modern/collapse_collapsed.png)