title: Manually allocating memory for a struct
body: <p>So I am working on a project in C where we need to implement malloc and free (meaning, we CANNOT use any C memory management functions such as malloc() or free()). This is only a code snippet, but it includes all relevant parts.</p>
  
  <pre><code>struct block_header
  {
      int size;
  };
  
  typedef struct FList_elem
  {
      struct block_header * header;
      struct list_elem elem;
  } FLelem;
  
  void * manual_malloc(size_t size)
  {
       freeBlock = (FLelem *) mem_sbrk(newsize);
  
       freeBlock-&gt;header = (struct block_header *) freeBlock;
       freeBlock-&gt;header-&gt;size = newsize;
  }
  </code></pre>
  
  <p>When allocating a new "block" of memory, we represent it via a structure FList_elem. In order to "allocate memory" for the struct, we point it at a memory address returned by mem_sbrk (works just like sbrk()). My question is, how do we establish memory for variables like size? Initially it's address is 0x0, and so assignments or references to it cause seg faults. Does it need to be a pointer so that we can set it's address, and then the value?</p>