Advertisement
a3f

counting function calls on windows

a3f
May 8th, 2014
501
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.58 KB | None | 0 0
  1. //explanation : https://www.facebook.com/groups/arabcpp/permalink/759109994119678/?comment_id=759169170780427&offset=0&total_comments=12
  2. // undefined behaviour (works on gcc)
  3. #include <windows.h>
  4. #include <stdio.h>
  5.  
  6. typedef double (*cos_t)(double);
  7. int cos_count = 0;
  8. double cos(double zawya)
  9. {
  10. cos_count++;
  11.  
  12. HINSTANCE c_runtime = LoadLibrary("msvcrt.dll"); // microsoft visual c runtime
  13. cos_t cos_ptr = (cos_t)GetProcAddress(c_runtime, "cos");
  14.  
  15. return cos_ptr(zawya);
  16. }
  17. int main (void)
  18. {
  19.     cos(2);
  20.     cos(2);
  21.     cos(2);
  22.  
  23.     printf("%d cosine functions were called", cos_count);
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement