Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

10
  • 2
    Basically you can use C++ as long as you don't (extensively) use: the standard library, exceptions, templates or rtti (do lambdas work? never tried). Whether you'd want to call the remaining language really 'c++' is another question. Commented Jan 25, 2018 at 11:22
  • 2
    @Voo: On the Arduino, templates are not necessarily a bad thing. Commented Jan 25, 2018 at 12:20
  • 2
    @Edgar Very clever trick, but certainly not the way you'd use templates in general code. A better way to phrase it might be that you have to be very careful with how you use templates since they can very easily lead to large quantities of code being generated behind your back. Commented Jan 25, 2018 at 13:46
  • 2
    @JAB It's generally recommended for efficient code to try and forward to non-generic functions (e.g. standard libraries cast T's to void* and deal with those). Absolutely doable but makes for awkward programming and is easily forgotten. Nick's template example is pretty similar: Instead of forwarding the byte* and size to a generic function we now have almost identical code multiple times in memory. If you had to write it by hand you'd notice the duplication. Commented Jan 26, 2018 at 21:35
  • 1
    @Curious The general gist is that C++ is complex enough that it can be rather hard to know what exactly the compiler is doing in the background. Then you also have to rely on your compiler to do certain optimizations for certain things to be feasible (do you know whether your compiler does COMDAT folding?). It can be done, usually by limiting yourself to certain features, but it's a bit fragile (i.e. a tiny change can lead to very different non-functional behavior). Commented Mar 1, 2023 at 11:26