[<<][c][>>][..]
Sat Jun 25 11:48:18 CEST 2011

Be careful with typeof() for casts in macros

Excerpt of a simple stack implementation.

  #define STACK_PUSH_SAFE(stack, thing, overflow) {       \
      void *room = stack_allot(stack);                    \
      if (!room) goto overflow;                           \
      *((typeof(thing)*)room) = thing;                    \
      }

The trouble with this is that the input argument of the macro is used
to determine the access.  So if the stack represents short ints (16
bits) and the type of the parameter at the call site is a 32bit int,
there is a problem:

  - data abort on ARM due to alignment problems

  - incorrect access (writes 2 values) on archs that support
    non-algined access

  



[Reply][About]
[<<][c][>>][..]