From f23d8a1fb412f469cf8e166e12b0fb9028aeeda5 Mon Sep 17 00:00:00 2001 From: jacekpoz Date: Mon, 11 Mar 2024 17:52:32 +0100 Subject: [PATCH] better casting --- lab01/zad1/src/main.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/lab01/zad1/src/main.c b/lab01/zad1/src/main.c index 8bea2c3..a139339 100644 --- a/lab01/zad1/src/main.c +++ b/lab01/zad1/src/main.c @@ -20,15 +20,14 @@ void test_queue(size_t size) { } for (size_t i = 0; i < 50; ++i) { - void *val_ptr = queue_read(q); - if (val_ptr == NULL) { + int64_t *val = (int64_t*)queue_read(q); + if (val == NULL) { printf("%zu: queue is empty!\n", i); break; } - int64_t val = *(int64_t*)val_ptr; - printf("%zu: read %ld from queue\n", i, val); - free(val_ptr); + printf("%zu: read %ld from queue\n", i, *val); + free(val); } queue_free(q); @@ -48,15 +47,14 @@ void test_stack(size_t size) { } for (size_t i = 0; i < 50; ++i) { - void *val_ptr = stack_pop(s); - if (val_ptr == NULL) { + int64_t *val = (int64_t*)stack_pop(s); + if (val == NULL) { printf("%zu: stack is empty!\n", i); break; } - int64_t val = *(int64_t*)val_ptr; - printf("%zu: popped %ld from stack\n", i, val); - free(val_ptr); + printf("%zu: popped %ld from stack\n", i, *val); + free(val); } stack_free(s);