Main: CONTRIBUTING.md: add a rule

This commit is contained in:
Alex Kotov 2022-06-15 13:10:44 +03:00
parent 0536bc47d5
commit 8503637778
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
4 changed files with 43 additions and 4 deletions

View File

@ -10,7 +10,40 @@ Common
C language
----------
Nothing here yet.
* Create `typedef`s with the names of related `struct`s. Use this name with a
prefix `struct` to declare the data itself, withoth the prefix to declare
a pointer or an array:
```c
typedef struct FooBar { int car; } *FooBar;
static struct FooBar FooBar_create();
static void FooBar_do_something(FooBar foobar);
// ...
struct FooBar foobar = FooBar_create();
FooBar foobar_ptr = &foobar;
FooBar_do_something(&foobar);
```
```c
typedef struct FooBar { int car; } FooBar[1];
static struct FooBar FooBar_create();
static void FooBar FooBar_init(FooBar foobar);
static void FooBar_do_something(FooBar foobar);
// ...
FooBar foobar = { FooBar_create() };
// or
FooBar foobar;
FooBar_init(foobar);
FooBar_do_something(foobar);
```

View File

@ -8,11 +8,9 @@
#define SIZE_512MiB ( 512 * 1024 * 1024)
#define SIZE_1GiB (1024 * 1024 * 1024)
KernAux_MemMap memmap;
int main()
{
KernAux_MemMap_init(memmap, SIZE_1GiB);
KernAux_MemMap memmap = { KernAux_MemMap_create(SIZE_1GiB) };
assert(KernAux_MemMap_add_entry(memmap, true, NULL, 0, SIZE_256MiB));
assert(KernAux_MemMap_add_entry(memmap, false, "foo", SIZE_256MiB, SIZE_256MiB));

View File

@ -26,6 +26,7 @@ typedef struct KernAux_MemMap {
struct KernAux_MemMap_Entry entries[KERNAUX_MEMMAP_ENTRIES_MAX];
} KernAux_MemMap[1];
struct KernAux_MemMap KernAux_MemMap_create(size_t memory_size);
void KernAux_MemMap_init(KernAux_MemMap memmap, size_t memory_size);
/// @warning Must only be called with unfinished memmap, otherwise panics.

View File

@ -12,6 +12,13 @@
#define MEMMAP (*memmap)
struct KernAux_MemMap KernAux_MemMap_create(const size_t memory_size)
{
struct KernAux_MemMap memmap;
KernAux_MemMap_init(&memmap, memory_size);
return memmap;
}
void KernAux_MemMap_init(KernAux_MemMap memmap, const size_t memory_size)
{
MEMMAP.is_finished = false;