瀏覽代碼

Fix printf with fixed u64/i64

Kajetan Johannes Hammerle 7 月之前
父節點
當前提交
3a169ac3a0
共有 4 個文件被更改,包括 17 次插入12 次删除
  1. 7 6
      performance/Main.c
  2. 3 2
      src/Test.c
  3. 4 2
      src/ToString.c
  4. 3 2
      test/modules/SpinLockTests.c

+ 7 - 6
performance/Main.c

@@ -1,3 +1,4 @@
+#include <inttypes.h>
 #include <stdio.h>
 
 #include "core/HashMap.h"
@@ -38,7 +39,7 @@ static void fillOrder(HashMapInt* m) {
     for(int i = 0; i < 10000; i++) {
         *putHashMapKeyInt(m, i) = i * i;
     }
-    printf("Fill Order: %ldns\n", getNanos() - nanos);
+    printf("Fill Order: %" PRId64 "ns\n", getNanos() - nanos);
 }
 
 static void fillChaos(HashMapInt* m) {
@@ -49,7 +50,7 @@ static void fillChaos(HashMapInt* m) {
         int r = randomI32(&random, 0, 10000);
         *putHashMapKeyInt(m, r) = r * r;
     }
-    printf("Fill Chaos: %ldns\n", getNanos() - nanos);
+    printf("Fill Chaos: %" PRId64 "ns\n", getNanos() - nanos);
 }
 
 static i64 average(HashMapInt* m, i64 (*f)(const HashMapInt* m), int n) {
@@ -65,8 +66,8 @@ static void order(int n) {
     initHashMapInt(&m);
     fillOrder(&m);
     puts("Order Probing");
-    printf("Search | %ld ms\n", average(&m, testSearch, n));
-    printf("EmptySearch | %ld ms\n", average(&m, testEmptySearch, n));
+    printf("Search | %" PRId64 " ms\n", average(&m, testSearch, n));
+    printf("EmptySearch | %" PRId64 " ms\n", average(&m, testEmptySearch, n));
     destroyHashMapInt(&m);
 }
 
@@ -75,8 +76,8 @@ static void chaos(int n) {
     initHashMapInt(&m);
     fillChaos(&m);
     puts("Chaos Probing");
-    printf("Search | %ld ms\n", average(&m, testSearch, n));
-    printf("EmptySearch | %ld ms\n", average(&m, testEmptySearch, n));
+    printf("Search | %" PRId64 " ms\n", average(&m, testSearch, n));
+    printf("EmptySearch | %" PRId64 " ms\n", average(&m, testEmptySearch, n));
     destroyHashMapInt(&m);
 }
 

+ 3 - 2
src/Test.c

@@ -1,5 +1,6 @@
 #include "core/Test.h"
 
+#include <inttypes.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -79,8 +80,8 @@ static bool addToResult(const char* file, bool comparison) {
     }
 
 TEST_NAMED_COMPARE(Int, int, "%d")
-TEST_NAMED_COMPARE(I64, i64, "%ld")
-TEST_NAMED_COMPARE(U64, u64, "%lu")
+TEST_NAMED_COMPARE(I64, i64, "%" PRId64)
+TEST_NAMED_COMPARE(U64, u64, "%" PRIu64)
 TEST_NAMED_COMPARE(Size, size_t, "%zu")
 TEST_NAMED_COMPARE(Bool, bool, "%d")
 

+ 4 - 2
src/ToString.c

@@ -1,5 +1,6 @@
 #include "core/ToString.h"
 
+#include <inttypes.h>
 #include <stdarg.h>
 #include <stdio.h>
 
@@ -45,10 +46,11 @@ size_t toStringBitArray(const BitArray* a, char* buffer, size_t n) {
         length--;
         for(size_t i = 0; i < length; i++) {
             u64 v = getBits(a, i);
-            stringAdd(&w, &buffer, &n, coreToString(buffer, n, "%lu, ", v));
+            stringAdd(&w, &buffer, &n,
+                      coreToString(buffer, n, "%" PRIu64 ", ", v));
         }
         u64 v = getBits(a, length);
-        stringAdd(&w, &buffer, &n, coreToString(buffer, n, "%lu", v));
+        stringAdd(&w, &buffer, &n, coreToString(buffer, n, "%" PRIu64, v));
     }
     stringAdd(&w, &buffer, &n, coreToString(buffer, n, "]"));
     return w;

+ 3 - 2
test/modules/SpinLockTests.c

@@ -1,3 +1,4 @@
+#include <inttypes.h>
 #include <stdio.h>
 #include <threads.h>
 
@@ -33,7 +34,7 @@ static void testMutex() {
     TEST_INT(40000, mc.counter);
 
     n += getNanos();
-    printf("%ldns Mutex\n", n);
+    printf("%" PRId64 "ns Mutex\n", n);
 }
 
 typedef struct {
@@ -64,7 +65,7 @@ static void testSpinLockLoop() {
     TEST_INT(40000, sc.counter);
 
     n += getNanos();
-    printf("%ldns SpinLock\n", n);
+    printf("%" PRId64 "ns SpinLock\n", n);
 }
 
 void testSpinLock() {