Menu

Home

Petr Pazourek

ECSTL - Embedded C Standard Template Library

The Embedded C Standard Template Library (ECSTL) is a software library for the C programming language. It is a clone of the C++ STL especially for embedded systems without using the heap (malloc/free functions).

Introduction

The ECSTL achieves its results through the use of macros. This approach provides compile-time polymorphism. Current focus is on implementation of a wide range of CPP STL containers.

Minimal example

Here is a minimal example using the queue container:

#include <stdio.h>
#include <stdlib.h>
#include <queue.h> // Step1: include the header.

// Step2: define queue's properties
DEFINE_QUEUE_TYPE(myqueue_int_t, int, 16);

int main(void)
{
    DEFINE_QUEUE(myqueue_int_t, myqueue); // Step3: define queue
    int sum = 0;

    QUEUE_PUSH(myqueue, 10); //insert data
    QUEUE_PUSH(myqueue, 20);
    QUEUE_PUSH(myqueue, 30);

    while(!QUEUE_EMPTY( myqueue ))
    {
        sum += *QUEUE_FRONT( myqueue ); //read data
        QUEUE_POP( myqueue ); //remove data
    }

    printf( "The elements of myqueue add up to %d\n", sum );
    printf( "\nThe final size of myqueue is %d\n", QUEUE_SIZE( myqueue ));
    return 0;
}

And its output:

The elements of myqueue add up to 60
The final size of myqueue is 0

Features

  • Very small
  • Easy to use
  • Headers only
  • No 3rd-party dependencies
  • Cross-platform: Windows, Linux, Mac OS X (gcc, clang, msvc, mingw, mingw-w64, c++builder)
  • Doesn't require C99

Usage

To start using ECSTL you need to make 2 simple steps.

Step 1: Adding includes

At first your project needs to know about ECSTL. For that you have to add ecstl/include to the project include paths.

Step 2: Using

The next step is to include files you need. All modules are created as special macros. For more information see original CPP STL documentation or a ECSTL doxygen documentation.

License

ECSTL is licensed under the MITBSD. You can freely use it in your commercial or opensource software.

Thread safety

This colection of containers is Not thread safe. The container functions should not be called concurrently by different threads. In case of necessity, use mutex or other ways to protect data from concurrent access.

Version history

Version 0.8 (6 May 2024)

  • fixed LIST container
  • fixed some MISRA-C 2004 violations in the list container

Version 0.7 (2 Dec 2021)

  • fixed a few MISRA-C:2004 violations
  • added a way to use the containers in a struct
  • removed standalone iterator template

Version 0.6 (21 Sep 2020)

  • added static initializers
  • fixed a missing include due to using a size_t type
  • code is C89 compliant

Version 0.5 (24 Nov 2017)

  • Initial public release
  • queue, deque, stack, list containers
  • list iterators

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.