Skip to content

C++ user module #14259

Answered by bikeNomad
ma261065 asked this question in ESP32
Apr 5, 2024 · 2 comments · 1 reply
Discussion options

You must be logged in to vote

You are correct (if I understand you correctly). C++ code can use C++ functions/methods internally; it's just that the functions that are called by Python code must be callable from C (no name mangling, etc.). You can ensure this by declaring them as extern "C" (with #ifdef __cplusplus guards). You also need to be careful with memory allocation, C++ exceptions and static guards, etc.

You could use a std::vector inside your C++ code, but if you wanted to provide it to MicroPython code it'd have to be presented as a bytes or array.array object or similar. You could use std::vector::cbegin() to get a pointer to the start of the allocated memory.

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@cnadler86
Comment options

Answer selected by ma261065
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
ESP32
Labels
None yet
3 participants