1. #include <stdio.h>
  2. #include "stringtable.h"
  3.  
  4. struct stringnode{
  5. hashcode_t key;
  6. cstring value;
  7. };
  8.  
  9. struct stringtable{
  10. size_t dim;
  11. size_t numEntries;
  12. stringnode_ref *nodes;
  13. };
  14.  
  15. stringtable_ref new_stringtable(){
  16. size_t index = 0;
  17. stringtable_ref sTable = malloc(sizeof(struct stringtable));
  18. sTable->dim = 31;
  19. sTable->numEntries;
  20. sTable->nodes = malloc(31 * sizeof(struct stringnode));
  21. for( index = 0; index < 31; index++ ){
  22. sTable->nodes[index]->key = 0;
  23. sTable->nodes[index]->value = NULL;
  24. }
  25. return sTable;
  26. }
  27.  
  28. #ifndef __STRINGTABLE_H__
  29. #define __STRINGTABLE_H__
  30.  
  31. #include <stdlib.h>
  32. #include <inttypes.h>
  33.  
  34. typedef char *cstring;
  35.  
  36. typedef uint32_t hashcode_t;
  37.  
  38. typedef stringtable *stringtable_ref;
  39.  
  40. typedef stringnode *stringnode_ref;
  41.  
  42. stringtable_ref new_stringtable();
  43.  
  44. #endif // __STRINGTABLE_H__
  45.  
  46. #include <stdlib.h>
  47. #include <stdio.h>
  48. #include "stringtable.h"
  49.  
  50. int main( int argc, char **argv ){
  51. stringtable_ref table = new_stringtable();
  52. return EXIT_SUCCESS;
  53. }
  54.  
  55. gcc -g -O0 -Wall -Wextra -std=gnu99 -c stringtable.c
  56. gcc -g -O0 -Wall -Wextra -std=gnu99 -c oc.c
  57. gcc -g -O0 -Wall -Wextra -std=gnu99 -o oc stringtable.o oc.o
  58.  
  59. sTable->nodes = malloc(31 * sizeof(struct stringnode));
  60. for( index = 0; index < 31; index++ ){
  61. sTable->nodes[index]->key = 0;
  62.  
  63. sTable->nodes[index] = malloc(sizeof(*(sTable->nodes[index])));
  64.  
  65. struct stringtable{
  66. size_t dim;
  67. size_t numEntries;
  68. stringnode_ref nodes;
  69. };
  70.  
  71. sTable->nodes[index].key = 0;
  72. sTable->nodes[index].value = NULL;
  73.  
  74. #include <stdlib.h>
  75.  
  76. typedef char *cstring;
  77.  
  78. struct stringnode{
  79. int key;
  80. cstring value;
  81. };
  82.  
  83. typedef struct stringnode *stringnode_ref;
  84.  
  85. struct stringtable{
  86. size_t dim;
  87. size_t numEntries;
  88. stringnode_ref nodes;
  89. };
  90.  
  91. typedef struct stringtable *stringtable_ref;
  92.  
  93. stringtable_ref new_stringtable(){
  94. size_t index = 0;
  95. stringtable_ref sTable = malloc(sizeof( *sTable ) ) ;
  96. sTable->dim = 31;
  97. sTable->nodes = malloc(31 * sizeof( *sTable->nodes ) ) ;
  98. for( index = 0; index < 31; index++ ){
  99. sTable->nodes[index].key = 0;
  100. sTable->nodes[index].value = NULL;
  101. }
  102. return sTable;
  103. }
  104.  
  105.  
  106. int main(int argc, char *argv[]) {
  107. stringtable_ref table = new_stringtable();
  108. exit( EXIT_SUCCESS ) ;
  109. }
  110.  
  111. :~/tmp$ gcc -g -O0 -Wall -Wextra -std=gnu99 -c stringtable.c
  112. In file included from stringtable.c:2:
  113. stringtable.h:11: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
  114. stringtable.h:13: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
  115. stringtable.h:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘new_stringtable’
  116. stringtable.c:12: error: expected specifier-qualifier-list before ‘stringnode_ref’
  117. stringtable.c:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘new_stringtable’