Advertisement
Guest User

Untitled

a guest
Jul 25th, 2014
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.67 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. rm -f a.out
  4. gcc -x c - <<EOF
  5. #include <stdio.h>
  6. #include <stdint.h>
  7.  
  8. unsigned long i;
  9. uint32_t prev_pid_time;
  10. #define LIMIT (300)
  11.  
  12. unsigned long Gettime(void) { return i; }
  13. uint16_t f() {
  14.   if(Gettime()>=prev_pid_time)
  15.     return Gettime() - prev_pid_time;
  16.   return LIMIT - prev_pid_time + Gettime();
  17. }
  18.  
  19. #define valid(a,b,c) \
  20.   i=b;prev_pid_time=a; \
  21.   printf("f(%3i,%3i)=%4i", a,b,f()); \
  22.   if(f()!=c) printf("<>%-3i - fail", c); \
  23.   else       printf("==%-3i", c); \
  24.   printf("\n");
  25.  
  26. int main() {
  27.   valid(  0, 2,   2);
  28.   valid(  2, 2,   0);
  29.   valid(  3, 2, 299);
  30.   valid(299, 2,   3);
  31.   valid(295, 0,   5);
  32.   return 0;
  33. }
  34. EOF
  35. ./a.out
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement