Background
I am learning low-level dev after working with C++ for high level projects for a decent stretch. Currently bumbling about typical C patterns and stumbling across bits of the linux kernel and old emails.
Question
Are there a set of commonly used/idiomatic macros, or generic functions which reduce repetition or reduce mistakes in memory allocation?
Something I see a lot in my code is long multiplication statements inside of malloc which I see as tedious, and a ripe place for problems. Example:
struct my_struct {
size_t size;
char* memory;
}
struct my_struct* my_struct_new(size_t size) {
struct my_struct* ms = malloc(sizeof *ms)
ms->size = size;
ms->memory = malloc(size * sizeof *ms->memory);
return ms;
}
I'm trying to avoid creating an XY problem through giving my bad tries here.
Thank you for your time.