CraftStruct2

Run Settings
LanguageC++
Language Version
Run Command
#include <stdio.h> #include <stdint.h> #include <stdlib.h> #include <string.h> #include <assert.h> #define forS0(Name, String) \ for(u32 Name = 0; Name == 0 || (String)[Name-1]; Name++) typedef uint64_t u64; typedef uint32_t u32; typedef uint16_t u16; typedef uint8_t u8; enum struct CraftStructEnum : u8{ Tnull, Ts64, Tstring }; struct CraftStructEntry{ CraftStructEnum type; u8 type_size; u8 word_size; int& E(char *member); }; CraftStructEntry *next(CraftStructEntry *in) { char *result = (char *)in; result += sizeof(CraftStructEntry); result += in->type_size; result += in->word_size; return (CraftStructEntry *)result; } int& CraftStructEntry::E(char *member) { CraftStructEntry *entry = this; int *result; while(1) { bool match = 1; if(entry->type == CraftStructEnum::Tnull) { entry->type = CraftStructEnum::Ts64; entry->type_size = 8; entry->word_size = 0; forS0(i, member) { ((char *)entry)[sizeof(CraftStructEntry)+i] = member[i]; entry->word_size++; } result = (int *)(((char *)entry) + sizeof(CraftStructEntry) + entry->word_size); // get value break; } for(int i = 0; member[i] != 0; ++i) { if(member[i] != ((char *)entry)[i+sizeof(CraftStructEntry)]) // get member { match = 0; break; } } if(match == 1) { result = (int *)(((char *)entry) + sizeof(CraftStructEntry) + entry->word_size); // get value break; } entry = next(entry); } return *result; } int main() { CraftStructEntry *Some_data = (CraftStructEntry *)calloc(1024 * 64, 1); Some_data->E("tega") = 1024; Some_data->E("fgg") = 32; printf("%lli, %lli, %lli", Some_data->E("fgg"), Some_data->E("tega"), Some_data->E("non_exist")); return 0; }
Editor Settings
Theme
Key bindings
Full width
Lines