ECSTL
The Embedded C Standard Template Library
stack.h File Reference
#include <stdint.h>

Macros

#define DEFINE_STACK_TYPE(typename, value_type, max_size)
 A new stack type definition. More...
 
#define DEFINE_STACK(typename, stack)
 A predefined stack definition with no elements. More...
 
#define STACK_PUSH(stack, value)
 Inserts a new element at the top of the stack. The content of this new element is initialized to a copy of val. More...
 
#define STACK_POP(stack)
 Removes the element on top of the stack. More...
 
#define STACK_TOP(stack)
 
#define STACK_EMPTY(stack)
 
#define STACK_SIZE(stack)
 
#define STACK_MAX_SIZE(stack)
 
#define STACK_CLEAR(stack)
 

Detailed Description

Stacks are a type of container, specifically designed to operate in a LIFO context (last-in first-out), where elements are inserted and extracted only from one end of the container.

Example:

#include <stdio.h>
#include <stdlib.h>
#include <stack.h>
DEFINE_STACK_TYPE(mystack_int_t, int, 16);
int main(void)
{
DEFINE_STACK(mystack_int_t, mystack);
STACK_PUSH(mystack, 10);
STACK_PUSH(mystack, 20);
*STACK_TOP(mystack) -= 5;
printf("mystack top() is now %d\n", *STACK_TOP(mystack));
return 0;
}

Output:

mystack top() is now 15

Macro Definition Documentation

◆ DEFINE_STACK

#define DEFINE_STACK (   typename,
  stack 
)

A predefined stack definition with no elements.

Parameters
typenameThe stack type
stackThe stack

◆ DEFINE_STACK_TYPE

#define DEFINE_STACK_TYPE (   typename,
  value_type,
  max_size 
)

A new stack type definition.

Parameters
typenameName of the new stack type
value_typeType of element.
max_sizeMaximal size of the stack. It defines the fixed-size of the static defined array.

◆ STACK_CLEAR

#define STACK_CLEAR (   stack)

Remove all elements from the stack.

Parameters
stackThe stack

◆ STACK_EMPTY

#define STACK_EMPTY (   stack)

Returns true if the stack is empty.

Parameters
stackThe stack

◆ STACK_MAX_SIZE

#define STACK_MAX_SIZE (   stack)

Returns the size() of the largest possible stack.

Parameters
stackThe stack

◆ STACK_POP

#define STACK_POP (   stack)

Removes the element on top of the stack.

Parameters
stackThe stack
Note
that no data is returned, and if the top element's data is needed, it should be retrieved before STACK_POP() is called.

◆ STACK_PUSH

#define STACK_PUSH (   stack,
  value 
)

Inserts a new element at the top of the stack. The content of this new element is initialized to a copy of val.

Parameters
stackThe stack
valueData to be added.

◆ STACK_SIZE

#define STACK_SIZE (   stack)

Returns the number of elements in the stack.

Parameters
stackThe stack

◆ STACK_TOP

#define STACK_TOP (   stack)

Returns a read/write pointer to the data at the top element of the stack. stack.

Parameters
stackThe stack