troydhanson / uthash

C macros for hash tables and more
Other
4.18k stars 926 forks source link

compile error on minimal programme #134

Closed mk270 closed 7 years ago

mk270 commented 7 years ago

I get a compile error compiling a minimal test programme:

$ ccomp -o utc.o -c utc.c
utc.c:19: warning: implicit declaration of function '__typeof' is invalid in C99 [-Wimplicit-function-declaration]
utc.c:19: error: called object type 'int' is neither a function nor function pointer

Where utc.c is:

#include <stdio.h>   /* gets */
#include <stdlib.h>  /* atoi, malloc */
#include <string.h>  /* strcpy */
#include "uthash.h"

struct my_struct {
    int id;                    /* key */
    char name[10];
    UT_hash_handle hh;         /* makes this structure hashable */
};

struct my_struct *users = NULL;

void add_user(int user_id, char *name) {
    struct my_struct *s;

    HASH_FIND_INT(users, &user_id, s);  /* id already in the hash? */
}
Quuxplusone commented 7 years ago

The error message seems accurate to me: '__typeof' is invalid in C99 Try compiling with a compiler that supports __typeof (GCC, Clang, etc), or adjusting your macro definitions until uthash decides to use a different way of computing the decltype of an expression. If all else fails, use -DNO_DECLTYPE (or the equivalent command-line option for your compiler).

mk270 commented 7 years ago

No, I know about the warning; that can be worked around as you suggest. The error, however,

$ utc.c:19: error: called object type 'int' is neither a function nor function pointer

seems a tougher nut to crack. I have dumped the preprocessor output and can't see where this "int" comes from.

Quuxplusone commented 7 years ago

https://www.sjbaker.org/wiki/index.php?title=A_Short_Guide_to_understanding_C%2B%2B_compiler_errors Fix the __typeof error, and the other one will disappear like magic!