Ad
  • Custom User Avatar

    Well, I was bored and wanted to make code as simple and fast as possible. By casting to unsigned* it adds '0's and copies the whole sequence (4 digits) in single-word instructions. Neither memcpy nor a custom loop generates such clean assembly (try it yourself on godbolt :).

  • Custom User Avatar

    But it actually works! Can I ask about your solution?
    Why do you use here your interesting type punning macro instead of memcpy() like this?:
    memcpy (&ph[1], &nums[0], 4);
    memcpy (&ph[6], &nums[3], 4);
    memcpy (&ph[10],&nums[6], 4);

  • Custom User Avatar

    C standard doesn't guarantee any function argument evaluation order so theoretically this code is undef behavior, although in practice not sure if there is a compiler that wouldn't evaluate the above left to right;