Macro to add file and line number to printf Source: http://www.decompile.com/cpp/faq/file_and_line_error_string.htm #define STRINGIFY(x) #x #define LINETOSTR(x) STRINGIFY(x) #define PRINTDEBUG(...) printf(__FILE__ ":" LINETOSTR(__LINE__) ": " __VA_ARGS__) Compile-time check for struct sizes #define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)])) int main(void) { BUILD_BUG_ON(sizeof(struct_type_t) != 8); } Performance timing struct timespec start = { 0 }; struct timespec stop = { 0 }; static uint64_t cumulativeTime = 0; static int32_t count = 0; clock_gettime(CLOCK_MONOTONIC_RAW, &start); // do stuff clock_gettime(CLOCK_MONOTONIC_RAW, &stop); cumulativeTime += ((stop.tv_sec * 1000000000LL) + stop.tv_nsec) - ((start.tv_sec * 1000000000LL) + start.tv_nsec); count++; if (0 == count % 256) { printf("time=%lu ns (n=%d)\n", cumulativeTime, count); cumulativeTime = 0; } |