From fb0e8a6fa561cd2a518b6a65f50e8179a19985cc Mon Sep 17 00:00:00 2001 From: Thomas Schmucker Date: Sun, 16 Jan 2022 10:41:49 +0100 Subject: feat: überflüssig Klammern bei sizeof-Operator entfernt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- allocator.h | 5 +---- arraylist.c | 8 ++++---- queue.c | 2 +- rb.c | 4 ++-- ringbuff.c | 6 ------ stack.c | 2 +- stack2.c | 4 ++-- tree.c | 4 ++-- 8 files changed, 13 insertions(+), 22 deletions(-) diff --git a/allocator.h b/allocator.h index fc28833..d47af52 100644 --- a/allocator.h +++ b/allocator.h @@ -1,5 +1,4 @@ -#ifndef ITS1_ALLOCATOR_H_INCLUDED -#define ITS1_ALLOCATOR_H_INCLUDED +#pragma once #include /* size_t */ @@ -29,5 +28,3 @@ void *its1_malloc_zero(struct its1_allocator *allocator, size_t n); #define NEW(ptr) ((ptr) = ALLOCATE(sizeof *(ptr))) #define NEW0(ptr) ((ptr) = ALLOCATE_ZERO(sizeof *(ptr))) - -#endif diff --git a/arraylist.c b/arraylist.c index cb23e94..f010d07 100644 --- a/arraylist.c +++ b/arraylist.c @@ -115,7 +115,7 @@ ArrayList_insertAt(struct ArrayList *arrayList, size_t idx, T *ptr) memmove(&arrayList->array[idx + 1], &arrayList->array[idx], - (arrayList->size - idx) * sizeof(arrayList->array[0])); + (arrayList->size - idx) * sizeof arrayList->array[0]); arrayList->array[idx] = ptr; ++arrayList->size; } @@ -158,7 +158,7 @@ ArrayList_removeAt(struct ArrayList *arrayList, size_t idx, void clear_func(T *, #if defined(ARRAYLIST_KEEP_ORDER) memmove(&arrayList->arrayList[idx], &arrayList->arrayList[idx + 1], - (arrayList->size - (idx + 1)) * sizeof(arrayList->arrayList[0])); + (arrayList->size - (idx + 1)) * sizeof arrayList->arrayList[0]); #else arrayList->array[idx] = arrayList->array[arrayList->size - 1]; #endif @@ -196,7 +196,7 @@ ArrayList_sort(struct ArrayList *arrayList, int cmp(const T *, const T *, void * }; // Das vollständige qsort_x()-Drama: https://stackoverflow.com/a/46042467 - qsort_r(arrayList->array, arrayList->size, sizeof(arrayList->array[0]), &context, ArrayList_qsortHelper); + qsort_r(arrayList->array, arrayList->size, sizeof arrayList->array[0], &context, ArrayList_qsortHelper); } bool @@ -243,7 +243,7 @@ ArrayList_binarySearch(struct ArrayList *arrayList, void *key, int cmp(void *, c .args = args }; - T **pos = bsearch(&context, arrayList->array, arrayList->size, sizeof(arrayList->array[0]), ArrayList_bsearchHelper); + T **pos = bsearch(&context, arrayList->array, arrayList->size, sizeof arrayList->array[0], ArrayList_bsearchHelper); if ( pos ) { *loc = (size_t)(pos - arrayList->array); return true; diff --git a/queue.c b/queue.c index 8533691..6a472ee 100644 --- a/queue.c +++ b/queue.c @@ -33,7 +33,7 @@ queue_put(struct queue *queue, T data) { struct queue_item *new_item; - if ( (new_item = malloc(sizeof(*new_item))) != NULL ) { + if ( (new_item = malloc(sizeof *new_item)) != NULL ) { struct queue_item *tmp = queue->tail; new_item->data = data; new_item->next = NULL; diff --git a/rb.c b/rb.c index ac21ec8..7c2d2c1 100644 --- a/rb.c +++ b/rb.c @@ -189,7 +189,7 @@ verify_property_5_helper(node n, int black_count, int *path_black_count) rbtree rbtree_create() { - rbtree t = malloc(sizeof(struct rbtree_t)); + rbtree t = malloc(sizeof *t); t->root = NULL; verify_properties(t); return t; @@ -198,7 +198,7 @@ rbtree_create() node new_node(void *key, void *value, color node_color, node left, node right) { - node result = malloc(sizeof(struct rbtree_node_t)); + node result = malloc(sizeof *result); result->key = key; result->value = value; result->color = node_color; diff --git a/ringbuff.c b/ringbuff.c index 2cd0062..1294b3b 100644 --- a/ringbuff.c +++ b/ringbuff.c @@ -106,12 +106,6 @@ ring_get(struct ring_buffer *rb, T *data) } /* -->8-- */ -void -f() -{ - ERROR(""); -} - void debug_print(const char *msg, struct ring_buffer *rb) { diff --git a/stack.c b/stack.c index 162324e..48b9eba 100644 --- a/stack.c +++ b/stack.c @@ -33,7 +33,7 @@ stack_push(struct stack *stack, T data) { struct stack_item *new_item; - if ( (new_item = malloc(sizeof(*new_item))) != NULL ) { + if ( (new_item = malloc(sizeof *new_item)) != NULL ) { new_item->data = data; new_item->next = stack->head; stack->head = new_item; diff --git a/stack2.c b/stack2.c index aa5d6ed..5f4ba41 100644 --- a/stack2.c +++ b/stack2.c @@ -28,7 +28,7 @@ bool stack_push(struct stack *stack, T data) { if ( stack->array == NULL ) { - if ( (stack->array = malloc(10 * sizeof(*stack->array))) != NULL ) { + if ( (stack->array = malloc(10 * sizeof *stack->array)) != NULL ) { stack->sz = 10; stack->p = 0; } @@ -42,7 +42,7 @@ stack_push(struct stack *stack, T data) size_t new_sz; T * new_array; - if ( (new_array = realloc(stack->array, (new_sz = (stack->sz * 3 / 2)) * sizeof(*stack->array))) != NULL ) { + if ( (new_array = realloc(stack->array, (new_sz = (stack->sz * 3 / 2)) * sizeof *stack->array)) != NULL ) { stack->array = new_array; stack->sz = new_sz; } diff --git a/tree.c b/tree.c index e6ee86e..93690e2 100644 --- a/tree.c +++ b/tree.c @@ -340,7 +340,7 @@ stack_push(struct stack *stack, struct tree_node *data) { struct stack_item *new_item; - if ( (new_item = malloc(sizeof(*new_item))) ) { + if ( (new_item = malloc(sizeof *new_item)) ) { new_item->data = data; new_item->next = stack->head; stack->head = new_item; @@ -426,7 +426,7 @@ queue_put(struct queue *queue, struct tree_node *data) { struct queue_item *new_item; - if ( (new_item = malloc(sizeof(*new_item))) ) { + if ( (new_item = malloc(sizeof *new_item)) ) { struct queue_item *tail; tail = queue->tail; -- cgit v1.3