I have a header file, where I try to collect global variable declarations. When trying to typedef a map I get the following error:

n file included from Dis0_10.ino:7:
/var/folders/jl/nv1qvh6n569cxq9xxfd6dx980000gn/T/build8295701509021940161.tmp/globals.h:23: error: expected initializer before '<' token

relevant code snippets from global.h are:

#ifndef GLOBALS
#define GLOBALS
#include <map>


typedef std::map<uint8_t,uint8_t> memmap_t;

I have no clue, why this statement should fail. I consider it rather straight forward. So I think there must be some problems of this kind here. Or am I missing another include?


The C++ standard library is not available for arduino.

Some implementations of similar containers or certain functions exist on the web, but for the most part the standard library is impractical on a device with such small amounts of both RAM and program memory.

An implementation of SGI STL for AVR has been documented here: http://andybrown.me.uk/wk/2011/01/15/the-standard-template-library-stl-for-avr-with-c-streams/

map is mentioned as being particularly impractical for anything less than an arduino mega(1280). An example of maps working is included on the page so it seems like a good lead if you really must use one, but I've never done this myself so I cant guarantee it still works.

  • 1
    In general, any sort of dynamic memory allocation is usually considered poor practices in embedded code development. – Connor Wolf Oct 18 '14 at 5:39
  • Ok this is definitely decision making information. I thought of map as a way of saving memory and cpu time. If the memory overhead is rather, I can go back to a sparse array and put into program memory. Thanks for the clue. – Ariser Oct 18 '14 at 8:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.