test/testatomic.c
changeset 3327 35387815b155
parent 3325 bb9c3d04f126
child 3338 9de326b3099c
     1.1 --- a/test/testatomic.c	Tue Sep 29 00:42:21 2009 +0000
     1.2 +++ b/test/testatomic.c	Tue Sep 29 01:19:14 2009 +0000
     1.3 @@ -1,5 +1,17 @@
     1.4  #include "SDL.h"
     1.5  
     1.6 +/* Make sure we have good macros for printing 32 and 64 bit values */
     1.7 +#ifndef PRIu32
     1.8 +#define PRIu32 "u"
     1.9 +#endif
    1.10 +#ifndef PRIu64
    1.11 +#ifdef __WIN32__
    1.12 +#define PRIu64 "I64u"
    1.13 +#else
    1.14 +#define PRIu64 "llu"
    1.15 +#endif
    1.16 +#endif
    1.17 +
    1.18  /*
    1.19    Absolutely basic tests just to see if we get the expected value
    1.20    after calling each function.
    1.21 @@ -44,72 +56,72 @@
    1.22  
    1.23     val32 = 0;
    1.24     tfret = SDL_AtomicTestThenSet32(&val32);
    1.25 -   printf("TestThenSet32        tfret=%s val=%d\n", tf(tfret), val32);
    1.26 +   printf("TestThenSet32        tfret=%s val=%"PRIu32"\n", tf(tfret), val32);
    1.27     tfret = SDL_AtomicTestThenSet32(&val32);
    1.28 -   printf("TestThenSet32        tfret=%s val=%d\n", tf(tfret), val32);
    1.29 +   printf("TestThenSet32        tfret=%s val=%"PRIu32"\n", tf(tfret), val32);
    1.30  
    1.31     SDL_AtomicClear32(&val32);
    1.32 -   printf("Clear32              val=%d\n", val32);
    1.33 +   printf("Clear32              val=%"PRIu32"\n", val32);
    1.34  
    1.35     ret32 = SDL_AtomicFetchThenIncrement32(&val32);
    1.36 -   printf("FetchThenIncrement32 ret=%d val=%d\n", ret32, val32);
    1.37 +   printf("FetchThenIncrement32 ret=%"PRIu32" val=%"PRIu32"\n", ret32, val32);
    1.38  
    1.39     ret32 = SDL_AtomicFetchThenDecrement32(&val32);
    1.40 -   printf("FetchThenDecrement32 ret=%d val=%d\n", ret32, val32);
    1.41 +   printf("FetchThenDecrement32 ret=%"PRIu32" val=%"PRIu32"\n", ret32, val32);
    1.42  
    1.43     ret32 = SDL_AtomicFetchThenAdd32(&val32, 10);
    1.44 -   printf("FetchThenAdd32       ret=%d val=%d\n", ret32, val32);
    1.45 +   printf("FetchThenAdd32       ret=%"PRIu32" val=%"PRIu32"\n", ret32, val32);
    1.46  
    1.47     ret32 = SDL_AtomicFetchThenSubtract32(&val32, 10);
    1.48 -   printf("FetchThenSubtract32  ret=%d val=%d\n", ret32, val32);
    1.49 +   printf("FetchThenSubtract32  ret=%"PRIu32" val=%"PRIu32"\n", ret32, val32);
    1.50  
    1.51     ret32 = SDL_AtomicIncrementThenFetch32(&val32);
    1.52 -   printf("IncrementThenFetch32 ret=%d val=%d\n", ret32, val32);
    1.53 +   printf("IncrementThenFetch32 ret=%"PRIu32" val=%"PRIu32"\n", ret32, val32);
    1.54  
    1.55     ret32 = SDL_AtomicDecrementThenFetch32(&val32);
    1.56 -   printf("DecrementThenFetch32 ret=%d val=%d\n", ret32, val32);
    1.57 +   printf("DecrementThenFetch32 ret=%"PRIu32" val=%"PRIu32"\n", ret32, val32);
    1.58  
    1.59     ret32 = SDL_AtomicAddThenFetch32(&val32, 10);
    1.60 -   printf("AddThenFetch32       ret=%d val=%d\n", ret32, val32);
    1.61 +   printf("AddThenFetch32       ret=%"PRIu32" val=%"PRIu32"\n", ret32, val32);
    1.62  
    1.63     ret32 = SDL_AtomicSubtractThenFetch32(&val32, 10);
    1.64 -   printf("SubtractThenFetch32  ret=%d val=%d\n", ret32, val32);
    1.65 +   printf("SubtractThenFetch32  ret=%"PRIu32" val=%"PRIu32"\n", ret32, val32);
    1.66  
    1.67  #ifdef SDL_HAS_64BIT_TYPE
    1.68     printf("\n64 bit -----------------------------------------\n\n");
    1.69  
    1.70     val64 = 0;
    1.71     tfret = SDL_AtomicTestThenSet64(&val64);
    1.72 -   printf("TestThenSet64        tfret=%s val=%llu\n", tf(tfret), ((unsigned long long)val64));
    1.73 +   printf("TestThenSet64        tfret=%s val=%"PRIu64"\n", tf(tfret), val64);
    1.74     tfret = SDL_AtomicTestThenSet64(&val64);
    1.75 -   printf("TestThenSet64        tfret=%s val=%llu\n", tf(tfret), ((unsigned long long)val64));
    1.76 +   printf("TestThenSet64        tfret=%s val=%"PRIu64"\n", tf(tfret), val64);
    1.77  
    1.78     SDL_AtomicClear64(&val64);
    1.79 -   printf("Clear64              val=%llu\n", ((unsigned long long)val64));
    1.80 +   printf("Clear64              val=%"PRIu64"\n", val64);
    1.81  
    1.82     ret64 = SDL_AtomicFetchThenIncrement64(&val64);
    1.83 -   printf("FetchThenIncrement64 ret=%llu val=%llu\n", ((unsigned long long)ret64), ((unsigned long long)val64));
    1.84 +   printf("FetchThenIncrement64 ret=%"PRIu64" val=%"PRIu64"\n", ret64, val64);
    1.85  
    1.86     ret64 = SDL_AtomicFetchThenDecrement64(&val64);
    1.87 -   printf("FetchThenDecrement64 ret=%llu val=%llu\n", ((unsigned long long)ret64), ((unsigned long long)val64));
    1.88 +   printf("FetchThenDecrement64 ret=%"PRIu64" val=%"PRIu64"\n", ret64, val64);
    1.89  
    1.90     ret64 = SDL_AtomicFetchThenAdd64(&val64, 10);
    1.91 -   printf("FetchThenAdd64       ret=%llu val=%llu\n", ((unsigned long long)ret64), ((unsigned long long)val64));
    1.92 +   printf("FetchThenAdd64       ret=%"PRIu64" val=%"PRIu64"\n", ret64, val64);
    1.93  
    1.94     ret64 = SDL_AtomicFetchThenSubtract64(&val64, 10);
    1.95 -   printf("FetchThenSubtract64  ret=%llu val=%llu\n", ((unsigned long long)ret64), ((unsigned long long)val64));
    1.96 +   printf("FetchThenSubtract64  ret=%"PRIu64" val=%"PRIu64"\n", ret64, val64);
    1.97  
    1.98     ret64 = SDL_AtomicIncrementThenFetch64(&val64);
    1.99 -   printf("IncrementThenFetch64 ret=%llu val=%llu\n", ((unsigned long long)ret64), ((unsigned long long)val64));
   1.100 +   printf("IncrementThenFetch64 ret=%"PRIu64" val=%"PRIu64"\n", ret64, val64);
   1.101  
   1.102     ret64 = SDL_AtomicDecrementThenFetch64(&val64);
   1.103 -   printf("DecrementThenFetch64 ret=%llu val=%llu\n", ((unsigned long long)ret64), ((unsigned long long)val64));
   1.104 +   printf("DecrementThenFetch64 ret=%"PRIu64" val=%"PRIu64"\n", ret64, val64);
   1.105  
   1.106     ret64 = SDL_AtomicAddThenFetch64(&val64, 10);
   1.107 -   printf("AddThenFetch64       ret=%llu val=%llu\n", ((unsigned long long)ret64), ((unsigned long long)val64));
   1.108 +   printf("AddThenFetch64       ret=%"PRIu64" val=%"PRIu64"\n", ret64, val64);
   1.109  
   1.110     ret64 = SDL_AtomicSubtractThenFetch64(&val64, 10);
   1.111 -   printf("SubtractThenFetch64  ret=%llu val=%llu\n", ((unsigned long long)ret64), ((unsigned long long)val64));
   1.112 +   printf("SubtractThenFetch64  ret=%"PRIu64" val=%"PRIu64"\n", ret64, val64);
   1.113  #endif
   1.114  
   1.115     return 0;