gcc 4.4.4 c89
Not sure why I am getting this error.
In my header file I have the following
handle.h
typedef struct Handle_t Handle
In my implementation file
handle.c
struct Handle {
size_t id;
char *name;
};
Handle* create_handle(size_t id)
{
Handle *hdev = NULL;
hdev = malloc(sizeof(*hdev)); /* Error */
.
.
}
Many thanks for any suggestions,
I used to get the typedef
wrong often until I started to think of it like two parts: type and def . The type first, then the inition of a new name. 从头。
typedef <type> <name>;
typedef struct Handle Handle_t; /* defines Handle_t as struct Handle */
typedef char *c_string; /* defines c_string as char * */
Your struct's name needs to match the typedef:
struct Handle_t {
/* ... */
};
typedef struct Handle_t Handle
您定义的结构称为Handle
,而不是Handle_t
,这是您键入的内容。
typedef struct Handle_t Handle
you type defined struct Handle_t to Handle, but the structure is Struct Handle,so either change struct Hadle to Struct handle_t or type def.
struct Handle_t
is not defined by the time the compiler reaches the line with the error.
you have defined a struct Handle
and aliased the type Handle
to the inexistent type struct Handle_t
. It's ok to have inexistent types for lots of things in C
, but not for a sizeof
argument.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.