mirror of
https://github.com/lloeki/cblocks-clobj.git
synced 2025-12-06 02:34:40 +01:00
pointers to object content, and matching (de)alloc
This commit is contained in:
parent
cbe43f63fd
commit
0191e7acf1
1 changed files with 8 additions and 3 deletions
11
main.c
11
main.c
|
|
@ -3,13 +3,16 @@
|
|||
#include <Block.h>
|
||||
|
||||
struct Post_s {
|
||||
char author[255];
|
||||
char body[2048];
|
||||
char *author;
|
||||
char *body;
|
||||
};
|
||||
typedef struct Post_s Post;
|
||||
|
||||
Post *Post_alloc() {
|
||||
return malloc(sizeof(Post));
|
||||
Post *new = malloc(sizeof(Post));
|
||||
new->author = malloc(255);
|
||||
new->body = malloc(1024);
|
||||
return new;
|
||||
}
|
||||
|
||||
void Post_init(Post *self) {
|
||||
|
|
@ -22,6 +25,8 @@ void Post_printf(Post *self) {
|
|||
}
|
||||
|
||||
void Post_dealloc(Post *self) {
|
||||
free(self->body);
|
||||
free(self->author);
|
||||
free(self);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue