I'm trying to compile a third party library, but for some reason I'm getting an error. The library is likely compiled differently. I've read up on the error but I can't seem to figure out what the issue is! :(
struct sfo_entry {
char* key;
size_t size;
size_t area;
void* value;
enum sfo_value_format format;
struct sfo_entry* next;
struct sfo_entry* prev;
};
struct sfo {
struct sfo_entry* entries;
};
bool sfo_load_from_memory(struct sfo* sfo, const void* data, size_t data_size) {
struct sfo_header* hdr;
struct sfo_table_entry* entry_table;
struct sfo_table_entry* entry;
entry_table = (struct sfo_table_entry*)(data + sizeof(*hdr));
// ...
return true;
}
The error is as follows:
sfo.cpp:150:47: error: arithmetic on a pointer to void
entry_table = (struct sfo_table_entry*)(data + sizeof(*hdr));
~~~~ ^
The error is that arithmetic is not allowed on pointers of type void *
, nor on pointers to any other incomplete type. This is consistent with the fact that pointer arithmetic is defined in terms of the size of the pointed-to type, which is unknown for incomplete types.
Some compilers implement an extension that would apply here, treating pointer arithmetic on void *
as if the pointed-to type had size 1. Often, this is exactly what the author of the code intended, as appears to be the case in your code. In that event, you could consider fixing this flaw in the code by changing the affected line to
entry_table = (struct sfo_table_entry*)((char *)data + sizeof(*hdr));