String Class?

Is there a C++ string class that is compatible with the Pokitto?
Including will not compile (shows cryptic error message about min and max macros).
And including <string.h> does not appear to have a string class.

Also, which category should general programming questions like this go under? I’m not showing a project, which most categories seem to be asking about. Sorry if this is not the right category :confused:

Thank you for any assistance with this :slight_smile:

I’m guessing the header string is trying to use std::min and std::max in its implementation, but because min and max are declared as macros the code won’t compile because macros have no concept of scope and thus make their names unusable by anything else. (I like to call this ‘macro bleed’ or ‘macro poisoning’.)

This is one of the reasons why function macros tend to be frowned upon.

I think you’ll either have to #undef min and #undef max or (if you need to keep the min and max macros for some reason) use #pragma push_macro and #pragma pop_macro (more info here).

There may or may not be other issues, I can’t really judge much without error messages or code.


(I think “projects and programming” might have been a more suitable category since part of the description is “ask questions”, but I’m not sure it matters too much. A moderator can probably move it anyway.)

Yeah, I was thinking the same thing. The Pokitto library defines min and max macros like the Arduino libraries. But the standard libraries (included queue I found out) defines min and max differently with an extra compare parameter. I’ll check into those pragma’s.

Thank you!

I had previously considered asking about having the min and max macros removed or replaced, but until now I didn’t have any tangible evidence they were causing problems.

I think now might be a good time to ask @jonne if it’s better to get rid of the min and max macros and recommend people use std::min and std::max.

They also declare regular 2-argument versions of min and max.
Those versions are templates that rely on an implementation of the < operator being available.

The 3-argument version is just to give the flexibility to allow custom comparison functions to be used.
For example, a case-insensitive string comparison or a comparison that only considers certain member variables.

If they’re not enough or you can’t get them to work, comment again and I’ll see if I can think of something.
(Or if I’m not around, someone else might think of something.)


The macros in the Arduino library have caused me issues in the past.
They’re the reason I had to suffix all the utility functions in my Fixed Point library with Fixed.
If they’d been template functions or regular functions I probably could have got away with not having the Fixed suffix.

are you using namespaces? i don’t recall having this problem for stl

Unrelated to the issue at hand, but it’s the standard library (or stdlib), not “stl”.

The STL (standard template library) was actually a different library that had a large influence on the stdlib (a bit like Boost).
For some reason there was a bit of confusion about it which stuck around and now some people erroneously call the stdlib “STL”.

Here’s an SO answer about it.

my bad, thats just what people told me.
also i recall some problems with min max before but its there for some arduino code or mbed reasons if i recall

No problem.
It’s a fairly widespread misconception sadly.

In all common code uses std::max andstd::min ought to be equally applicable and either generate the same amount of code or be cheaper*.

The only issues I can see is if it’s being tested for with preprocessor commands or used in code that can’t be changed to use std::.


* When I was working on Dark & Under, one of the changes I made to save space was to swap the abs macro for a self-made template version of abs. The compiler was able to optimse the template better than the macro.

hang on im trying to recreate the error and dont seem to get it at all.
also if this error pops up using #define DISABLEAVRMIN should fix it if im not mistaken