我一直在研究问题集拼写器的最后几天,到目前为止这就是我所拥有的。 不幸的是,它没有编译,我有点迷失。 如果有人可以帮助我告诉我,我做错了什么,我将非常感激。
// Implements a dictionary's functionality #include #include #include #include #include #include "dictionary.h" #define HASHTABLE_SIZE 65536 // A struct for a node typedef struct node { // Length is up to 45 + 1 for the Null char word[LENGTH + 1]; // A pointer to the next node struct node *next; } node; node *hashtable[HASHTABLE_SIZE]; node *head = NULL; // Hashes words // Thanks to the husband of reddit user delipity for providing the function // https://www.reddit.com/r/cs50/comments/1x6vc8/pset6_trie_vs_hashtable/ int hash_it(char *word) { unsigned int hash = 0; for (int i = 0, n = strlen(word); i < n; i++) { hash = (hash < word, copyWord) == 0) { return true; } else { // Move the cursor to the next node cursor = cursor -> next; } } return false; } // Loads dictionary into memory, returning true if successful else false bool load(const char *dictionary) { // Load up a file and open it for reading FILE *file; file = fopen(dictionary, "r"); char word[LENGTH + 1]; // Making each of buckets of the table NULL for (int i = 0; i word, word); // Hashing the word and getting the index hashIndex = hash_it(word); // Pointing to the first element of the table new_node -> next = head; // Assigning the head to be the new element head = new_node; // Hashing the word and inserting a word to that place hashtable[hashIndex] = new_node; counter++; } // After the dictionary is loaded, close the file and return true fclose(file); return true; } // Returns number of words in dictionary if loaded else 0 if not yet loaded unsigned int size(void) { // TODO return counter; } // Unloads dictionary from memory, returning true if successful else false bool unload(void) { // Make a cursor pointing to the head node *cursor = head; while (cursor != NULL) { // A temporary node pointing to cursor node *temp = cursor; // Move the cursor to next cursor = cursor -> next; // Free the temp free(temp); } return true; // When to return false? }
在所有函数中,我得到了几个未定义的引用和无效的符号索引,它们不允许代码编译:
undefined reference to `__ubsan_handle_nonnull_arg' undefined reference to `__ubsan_handle_shift_out_of_bounds' undefined reference to `__ubsan_handle_type_mismatch' undefined reference to `__ubsan_handle_add_overflow' undefined reference to `__ubsan_handle_divrem_overflow'
您没有提供有关如何编译代码的详细信息,但我怀疑您在LDFLAGS
中缺少-fsanitize=undefined
。
以上就是c/c++开发分享未定义的引用`__ubsan_handle_nonnull_arg’相关内容,想了解更多C/C++开发(异常处理)及C/C++游戏开发关注计算机技术网(www.ctvol.com)!)。
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/c-cdevelopment/522178.html