HackerTrans
TopNewTrendsCommentsPastAskShowJobs

laanaah

no profile record

comments

laanaah
·3 yıl önce·discuss
The way I usually deal with this nonsense is to write a function in assembly that returns its pointer argument:

  stop_messing_with_my_code:
    mov rax, rdi
    ret

  extern "C" void *stop_messing_with_my_code(void *);

  void *p = stop_messing_with_my_code(malloc(100));
  // compiler cant know what my function does, it might have initialized it,
  // aligned it properly, returned the correct, type, etc.
Also useful for getting around the idiotic type-based aliasing so you can write custom allocators (i.e a byte pool allocated statically/globally, then allocate data from that which is common in embedded, which is technically not possible in standard C or C++...)