memcpy problems when switching from arduino to espIDF
Posted: Mon Mar 25, 2024 9:30 pm
Been working on moving an arduino framed project into a native IDF (4.4.7), for the first time. I worked through my arduino version to try and make it as compatible as possible before moving it over....removing String** usage & such.
My program uses a linked list with a void *data pointer that points to different types of structures. The nodes store the type, so accessing is just a matter of reading *data into a structure of the appropriate type. To do this, I use memcpy. Worked fine in my arduino version, but in IDF I've got some 80 errors like:
here is the node struct for the linked list:
here is what one of the structs looks like:
Not gonna pretend to understand the error, but it seems like its because I have "non-trival members" of that struct (Rect, FontInfo, std:string)
here are the memcpy's I use to read & right to the node data: (read node is a temp instance of fNode, the linked list struct)
seems like its ok with my write function, but flags errors on all the reads (some 80+ of them).
So first of all, I really need to understand why this wasn't a problem in arduino, and is in IDF? I know arduino framework has its differences, but this seems like straight C++ stuff.
Second, I need to figure out how to correct this. Kinda spinning my wheels on that right now. Do I need to write copy constructors for each of the structures? Do I need to use a different command to copy? Do I actually have a code issue, or do I need to fix something with the compiler? I mean, it all worked fine in arduino....
I can write some code, but I am by no means a programmer. Please keep that in mind with your responses.
Thanks so much for your attention, without community support like this, I could never accomplish the things do.
**on a side note, I had been working to break my use of String(arduino), after I read up on the problems it can make. In replacing all the String references, I used a mix of c and c++ strings (char *str & std::string). After using c++ strings, I saw they can do most of the things a String(ard) can do. Do they come with the same pitfalls of String? If not, why was the adruino String ever made?
My program uses a linked list with a void *data pointer that points to different types of structures. The nodes store the type, so accessing is just a matter of reading *data into a structure of the appropriate type. To do this, I use memcpy. Worked fine in my arduino version, but in IDF I've got some 80 errors like:
Code: Select all
void* memcpy(void*, const void*, size_t)' writing to an object of type 'struct butData' with no trivial copy-assignment; use copy-assignment or copy-initialization instead [-Werror=class-memaccess]",
Code: Select all
typedef struct fNode
{
void *data;
uint8_t type;
uint16_t flags;
}fNode;
here is what one of the structs looks like:
Code: Select all
typedef struct butData
{
uint8_t ID, type;
uint8_t mouseState:3;
Rect absPos;
int8_t txtStartOffset;
std::string fieldText;
fabgl::FontInfo const* fieldFont;
uint8_t bg0, fg0, bg1, fg1, hoverColor, clickColor;
}butData;
here are the memcpy's I use to read & right to the node data: (read node is a temp instance of fNode, the linked list struct)
Code: Select all
memcpy(&curButData, readNode.data, sizeof(curButData)); // read
memcpy(readNode.data, &curButData, sizeof(curButData)); //write
So first of all, I really need to understand why this wasn't a problem in arduino, and is in IDF? I know arduino framework has its differences, but this seems like straight C++ stuff.
Second, I need to figure out how to correct this. Kinda spinning my wheels on that right now. Do I need to write copy constructors for each of the structures? Do I need to use a different command to copy? Do I actually have a code issue, or do I need to fix something with the compiler? I mean, it all worked fine in arduino....
I can write some code, but I am by no means a programmer. Please keep that in mind with your responses.
Thanks so much for your attention, without community support like this, I could never accomplish the things do.
**on a side note, I had been working to break my use of String(arduino), after I read up on the problems it can make. In replacing all the String references, I used a mix of c and c++ strings (char *str & std::string). After using c++ strings, I saw they can do most of the things a String(ard) can do. Do they come with the same pitfalls of String? If not, why was the adruino String ever made?