Typedefs for pointer types are often a bad idea, since they can make it difficult to tell whether a type name refers to a pointer type or not.
Suggestion:
typedef struct { /* ... */ } object_t;
object_t *obj1 = malloc(sizeof *obj1);
And if you want to allocate space for an array of N objects:
object_t *obj1 = malloc(N * sizeof *obj1);
Note that I've removed the leading underscore from the type name. Identifiers starting with underscores are reserved to the implementation; you shouldn't define them in your own code.
The malloc(sizeof *foo)
idiom may take a little getting used to, but it means you don't have to specify the type name more than once, which avoids errors. (The *obj1
doesn't actually dereference obj1
, since the operand of sizeof
is not evaluated.)
In your code:
object_t obj1 = malloc(sizeof(object_t));
since object_t
is a pointer type, you're allocating enough memory to hold a pointer object, not a structure object. (Using such similar names object_t
and _object_t
for the pointer and struct types, respectively, undoubtedly contributed to the confusion.)