Copilot oftewel Artificial Intelligence werkt erg goed tegenwoordig. Ik stel de volgende vraag:
"How to determine the byte position of an element in a C struct"
Vroeger kon je het vergeten dat je antwoord kreeg via Google. Tegenwoordig krijg je het antwoord:
#include <stdio.h>
#include <stddef.h> // For offsetof macro
struct MyStruct {
int a;
float b;
char c;
};
int main() {
// Calculate and print the offset of each member
printf("Offset of 'a': %zu bytes\n", offsetof(struct MyStruct, a));
printf("Offset of 'b': %zu bytes\n", offsetof(struct MyStruct, b));
printf("Offset of 'c': %zu bytes\n", offsetof(struct MyStruct, c));
return 0;
}
En daarmee kon ik mijn oplossing gemakkelijk programmeren:
int theOffset = offsetof(SDL_KeyboardEvent, scancode);
AI werkt goed!