Actually, you can simplify the fix thusly: diff = (long long)(now.tv_sec - then.tv_sec) * 1000000 + (now.tv_usec - then.tv_usec);
Соглашаюсь с условиями обработки персональных данных