Using C++17 for new esp32-s3(Flash:16/8MB,RAM:8MB)

quantum
Posts: 2
Joined: Tue May 28, 2024 7:51 am

Using C++17 for new esp32-s3(Flash:16/8MB,RAM:8MB)

Postby quantum » Tue May 28, 2024 9:02 am

Dear Experts,

I am going to use C++17 to compile my program ... Traditionally, C language is used to program microcontrollers. On the other hand, I need to use C++ for my project . When we read comments of experts on the Internet, some of them suggest NOT to use Template at all, when using C++ for microcontrollers, but I need to take advantage of : "Template meta programming in C++ .

Also, when we consider limitation of ESP-IDF for C++,on their website, they mentioned :

**Various section attributes (such as IRAM_ATTR) are ignored when used with template functions.**

(Please see this link: https://stackoverflow.com/questions/743 ... n-template)

Here are my questions:

1-Can I use C++17 ,in my project without any problem when I use Templates?

2-What is my best option to program new esp32-s3 boards with C++17(DevKit-C1 for example, Flash: 16/8MB - RAM: 8MB ) :
a)ESP-IDF and VSCode
b)Arduino IDE for windows
c)Platformio extension for VScode

Which one: a, b or c?

3-Is there any suggestion or comment to consider when we use C++17 for this new esp32-s3 boards?

Your consideration is highly appreciated.
Regards,
Quantum.

ESP_Sprite
Posts: 9724
Joined: Thu Nov 26, 2015 4:08 am

Re: Using C++17 for new esp32-s3(Flash:16/8MB,RAM:8MB)

Postby ESP_Sprite » Wed May 29, 2024 1:00 am

quantum wrote:
Tue May 28, 2024 9:02 am
1-Can I use C++17 ,in my project without any problem when I use Templates?
Seemingly, unless you use attributes. I'm not sure how relevant that issue still is, but not being able to handle attributes will mostly affect the placement of functions in IRAM, and you can get around that by simply not having templates for anything that happens in interrupt handlers or callbacks that run in an interrupt context.


2-What is my best option to program new esp32-s3 boards with C++17(DevKit-C1 for example, Flash: 16/8MB - RAM: 8MB ) :
a)ESP-IDF and VSCode
b)Arduino IDE for windows
c)Platformio extension for VScode

Which one: a, b or c?
Whichever one you like. All are based on ESP-IDF, which provides the C++ support.

3-Is there any suggestion or comment to consider when we use C++17 for this new esp32-s3 boards?
IDF v5.1 already uses C++23, so C++17 is supported by default.

MicroController
Posts: 1701
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: Using C++17 for new esp32-s3(Flash:16/8MB,RAM:8MB)

Postby MicroController » Wed May 29, 2024 9:02 pm

When we read comments of experts on the Internet, some of them suggest NOT to use Template at all, when using C++ for microcontrollers,
Likely the same crowd who tell you that you can use C89 - if you're not serious enough to program in assembly.
I found that templates are extremely valuable, especially for MCU programming. With MCUs' constraints of RAM and CPU power, and with one binary only ever running in one specific hardware environment, it's very beneficial to push as much work as possible to the compiler instead of doing it at runtime. ("compile-time polymorphism",...)

I'm not sure what the actual current state of gcc, gcc's attributes, C++ attributes, and template functions is, but I don't find it hard to just avoid having to use (section) attributes on template functions.
3-Is there any suggestion or comment to consider when we use C++17 ... ?

1) Talking about C++ things that don't work: Calling virtual member functions in an IRAM-only context (IRAM-ISR) does not work.
2) Don't use C++17. Go straight for C++20 (or later) - concepts are really helpful when templating.

quantum
Posts: 2
Joined: Tue May 28, 2024 7:51 am

Re: Using C++17 for new esp32-s3(Flash:16/8MB,RAM:8MB)

Postby quantum » Tue Jun 04, 2024 8:25 am

Dear @ESP_Sprite & @Microcontroller,

Thank you for your time and attention to reply to my questions. I really appreciate that .
Regarding my second question:

I assume : Arduino can not support full features of C++,specially when using Templates . Arduino facilitates working with microcontrollers in some ways, but it has downsides, probably . Do you agree?

Regards,
quantum.

ESP_Sprite
Posts: 9724
Joined: Thu Nov 26, 2015 4:08 am

Re: Using C++17 for new esp32-s3(Flash:16/8MB,RAM:8MB)

Postby ESP_Sprite » Tue Jun 04, 2024 12:04 pm

That's very hard to say. Obviously Arduino, like every SDK, has its downsides. I don't think Arduino has any additional restrictions on templates than any SDK has.

Who is online

Users browsing this forum: No registered users and 172 guests