Quick actions

cmd+k|ctrl+k

Navigation

Languages

KeyValue

Snippet info

Language

C

Visibility

public

Author

evine

Created

2016-01-17T23:44:28Z

Updated

2016-01-18T00:32:43Z

#include <stdio.h>


#define KeyValueTypeDefine(Type) \
typedef struct          \
{                       \
    char *Key;          \
    Type Value;         \
}KeyValueStruct_##Type;

// You can only use these exact type-names you define.
KeyValueTypeDefine(int);
KeyValueTypeDefine(short);
KeyValueTypeDefine(char);

#define KeyValue(Type,VariableName,ValueInput)  \
KeyValueStruct_##Type VariableName;             \
VariableName.Key = #VariableName;               \
VariableName.Value = ValueInput



int main()
{
    
    KeyValue(char,SomeName,255);
    
    printf("%s\n",SomeName.Key);    // String
    printf("%i\n",SomeName.Value);  // Value of some Type
    printf("%lu\n",sizeof(SomeName));
    return 0;
}
INFO