dimonomid / tneo

TNeo: a well-formed and carefully tested preemptive real-time kernel for 16- and 32-bits MCUs
https://dmitryfrank.com/articles/how_i_ended_up_writing_my_own_kernel
233 stars 49 forks source link

cast-align issues in tn_fmem_create #7

Open travisgriggs opened 6 years ago

travisgriggs commented 6 years ago

I'm trying to use tneo in my samd21 (m0+) project. Since I have my own build engine based on python, I'm doing the "build manually" route. One of the options I compile with is -Wcast-align. However, doing so is producing the following error:

/Users/travisg/Projects/twig_lora_tneo/TNEO/core/tn_fmem.c: In function 'tn_fmem_create':
/Users/travisg/Projects/twig_lora_tneo/TNEO/core/tn_fmem.c:333:20: error: cast increases required alignment of target type [-Werror=cast-align]
          p_tmp   = (void **)p_block;

I'm not sure what the best way to get around this is. I can remove that option, but once upon a time, I had convinced myself that was a good thing to check for.

ghost commented 6 years ago

I think as both start_address and block_size are aligned values, you are safe to use void instead of unsigned char here, so the whole block would be:

      void **p_tmp;
      void *p_block;
      int i;

      p_tmp    = (void **)fmem->start_addr;
      p_block = (unsigned char*)fmem->start_addr + fmem->block_size;
      .... loop comes here 

But then of course you'll get "pointer of type ‘void *’ used in arithmetic", i've fixed it in this way:

p_block = (unsigned char *)p_block + fmem->block_size;