mirror of
https://github.com/lloeki/cblocks-clobj.git
synced 2025-12-06 02:34:40 +01:00
basic object-like system in C
This commit is contained in:
commit
6a6cbef986
3 changed files with 37 additions and 0 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
main
|
||||
*.o
|
||||
6
Makefile
Normal file
6
Makefile
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
all: main
|
||||
|
||||
main: main.o
|
||||
|
||||
clean:
|
||||
rm -f main.o main
|
||||
29
main.c
Normal file
29
main.c
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <Block.h>
|
||||
|
||||
struct Post_s {
|
||||
char author[255];
|
||||
char body[2048];
|
||||
};
|
||||
typedef struct Post_s Post;
|
||||
|
||||
Post *Post_alloc() {
|
||||
return malloc(sizeof(Post));
|
||||
}
|
||||
|
||||
void Post_init(Post *self) {
|
||||
*self->author = '\0';
|
||||
*self->body = '\0';
|
||||
}
|
||||
|
||||
void Post_dealloc(Post *self) {
|
||||
free(self);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
Post *post = Post_alloc();
|
||||
printf("%s\n\n%s\n", post->author, post->body);
|
||||
Post_dealloc(post);
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue