From 3bb59bf41c8b923a1fe703ac81fdb3311b1826a1 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Wed, 28 Nov 2012 20:38:31 +0000 Subject: [PATCH] core: Fix some C99/C90 warnings If these files were used by a project which compiled using C90 with -Wall, warnings would be emitted about declarations in the middle of blocks. --- simavr/sim/sim_avr.h | 2 +- simavr/sim/sim_regbit.h | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/simavr/sim/sim_avr.h b/simavr/sim/sim_avr.h index db41e41..ccc5c88 100644 --- a/simavr/sim/sim_avr.h +++ b/simavr/sim/sim_avr.h @@ -286,7 +286,7 @@ typedef struct avr_t { // this is a static constructor for each of the AVR devices typedef struct avr_kind_t { const char * names[4]; // name aliases - avr_t * (*make)(); + avr_t * (*make)(void); } avr_kind_t; // a symbol loaded from the .elf file diff --git a/simavr/sim/sim_regbit.h b/simavr/sim/sim_regbit.h index 4852b56..96941c2 100644 --- a/simavr/sim/sim_regbit.h +++ b/simavr/sim/sim_regbit.h @@ -43,9 +43,11 @@ extern "C" { static inline uint8_t avr_regbit_set(avr_t * avr, avr_regbit_t rb) { uint8_t a = rb.reg; + uint8_t m; + if (!a) return 0; - uint8_t m = rb.mask << rb.bit; + m = rb.mask << rb.bit; avr_core_watch_write(avr, a, avr->data[a] | m); return (avr->data[a] >> rb.bit) & rb.mask; } @@ -53,9 +55,11 @@ static inline uint8_t avr_regbit_set(avr_t * avr, avr_regbit_t rb) static inline uint8_t avr_regbit_setto(avr_t * avr, avr_regbit_t rb, uint8_t v) { uint8_t a = rb.reg; + uint8_t m; + if (!a) return 0; - uint8_t m = rb.mask << rb.bit; + m = rb.mask << rb.bit; avr_core_watch_write(avr, a, (avr->data[a] & ~(m)) | ((v << rb.bit) & m)); return (avr->data[a] >> rb.bit) & rb.mask; } @@ -66,9 +70,11 @@ static inline uint8_t avr_regbit_setto(avr_t * avr, avr_regbit_t rb, uint8_t v) static inline uint8_t avr_regbit_setto_raw(avr_t * avr, avr_regbit_t rb, uint8_t v) { uint8_t a = rb.reg; + uint8_t m; + if (!a) return 0; - uint8_t m = rb.mask << rb.bit; + m = rb.mask << rb.bit; avr_core_watch_write(avr, a, (avr->data[a] & ~(m)) | ((v) & m)); return (avr->data[a]) & (rb.mask << rb.bit); } @@ -111,8 +117,9 @@ static inline uint8_t avr_regbit_clear(avr_t * avr, avr_regbit_t rb) static inline uint8_t avr_regbit_get_array(avr_t * avr, avr_regbit_t *rb, int count) { uint8_t res = 0; + int i; - for (int i = 0; i < count; i++, rb++) if (rb->reg) { + for (i = 0; i < count; i++, rb++) if (rb->reg) { uint8_t a = (rb->reg); res |= ((avr->data[a] >> rb->bit) & rb->mask) << i; } -- 2.39.5