blog

Personal blog
git clone git://git.laack.co/blog.git
Log | Files | Refs

c-macros.md (649B)


      1 # C-Macros
      2 
      3 What are they able to do / not do?
      4 
      5 ---
      6 
      7 They can do basic function wrapping with VA_ARGS:
      8 
      9 ```c
     10 #define TIME_BLOCK_EXEC(name, ...) do {                                     \
     11     uint64_t start = rdtsc();                                               \
     12     __VA_ARGS__;                                                            \
     13     uint64_t end = rdtsc();                                                 \
     14   	printf("%s\t\t%lld\n", name, end - start);                              \
     15 } while(0);
     16 ```
     17 
     18 Assuming there's an rdtsc function that calls the similarly named intrinsic, this will get the ts before and after VA_ARGS execution.