fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. #define node(name, key_t, value_t) \
  5.   typedef struct { \
  6.   key_t key; \
  7.   value_t value; \
  8.   } name; \
  9.  
  10. int main(int argc, const char * argv[]) {
  11. node(stringIntNode, char*, int);
  12. stringIntNode* n = malloc(sizeof(stringIntNode*));
  13. n->key = "first";
  14. n->value = 1;
  15.  
  16. printf("the node n has a key of %s and a value of %d.\n", n->key, n->value);
  17.  
  18. // error starts from here
  19. node(charStringNode, char, char*);
  20. charStringNode* n2 = malloc(sizeof(charStringNode*));
  21. n2->key = 'a';
  22. n2->value = "first";
  23.  
  24. printf("the node n2 has a key of %c and value of %s.\n", n2->key, n2->value);
  25.  
  26. return 0;
  27. }
Success #stdin #stdout 0s 1832KB
stdin
Standard input is empty
stdout
the node n has a key of first and a value of 1.
the node n2 has a key of a and value of first.