Structuring the Document

  • + 1 comment

    Lolwut?

    nesting a structure inside a structure is just and plainly a bad idea

    Structures containing pointers to other structures are common and idiomatic in C... essentially every graph data structure uses such pointers to represent edges. A classic linked list, for example:

    struct node {
    	int data;
    	struct node *next;
    }
    

    the second outer structure will be allocated... overwriting the first inner structure

    Malloc will never return a memory block that aliases any block it previously returned until that block has been free()'d. In the situation you describe, malloc would simply allocate room for the second outer structure after the first inner structure.

    the allocation of memory might differ after a new compilation

    Allocations using malloc are resolved at run-time, not compile-time. The only memory allocations resolved at compile-time are variables with automatic and static storage classes. Y-You aren't allocating the whole data structure on the stack, are you?