From: bernie Date: Mon, 20 Sep 2004 03:31:27 +0000 (+0000) Subject: Sanitize for C++. X-Git-Tag: 1.0.0~1022 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=018b68ae17c81e82f8a1991f518c08107657bc9b;p=bertos.git Sanitize for C++. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@219 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/debug.h b/debug.h index 6c38650b..7daee2c3 100755 --- a/debug.h +++ b/debug.h @@ -17,6 +17,9 @@ /*#* *#* $Log$ + *#* Revision 1.3 2004/09/20 03:31:27 bernie + *#* Sanitize for C++. + *#* *#* Revision 1.2 2004/09/14 21:01:46 bernie *#* Mark assertions as LIKELY(). *#* @@ -191,15 +194,15 @@ int __check_wall(long *wall, int size, const char *name, const char *file, int line); #ifndef CONFIG_KDEBUG_ASSERT_NO_TEXT - #define ASSERT(x) (LIKELY(x) ? 0 : __assert(#x, THIS_FILE, __LINE__)) - #define ASSERT2(x, help) (LIKELY(x) ? 0 : __assert(help " (" #x ")", THIS_FILE, __LINE__)) + #define ASSERT(x) ((void)(LIKELY(x) ? 0 : __assert(#x, THIS_FILE, __LINE__))) + #define ASSERT2(x, help) ((void)(LIKELY(x) ? 0 : __assert(help " (" #x ")", THIS_FILE, __LINE__))) #else - #define ASSERT(x) (LIKELY(x) ? 0 : __assert("", THIS_FILE, __LINE__)) - #define ASSERT2(x, help) ASSERT(x) + #define ASSERT(x) ((void)(LIKELY(x) ? 0 : __assert("", THIS_FILE, __LINE__))) + #define ASSERT2(x, help) ((void)ASSERT(x)) #endif - #define ASSERT_VALID_PTR(p) (LIKELY((p) >= 0x200) ? 0 : __invalid_ptr(p, #p, THIS_FILE, __LINE__)) - #define ASSERT_VALID_PTR_OR_NULL(p) (LIKELY((p == NULL) || ((p) >= 0x200)) ? 0 : __invalid_ptr((p), #p, THIS_FILE, __LINE__)) + #define ASSERT_VALID_PTR(p) ((void)(LIKELY((p) >= 0x200) ? 0 : __invalid_ptr(p, #p, THIS_FILE, __LINE__))) + #define ASSERT_VALID_PTR_OR_NULL(p) ((void)(LIKELY((p == NULL) || ((p) >= 0x200)) ? 0 : __invalid_ptr((p), #p, THIS_FILE, __LINE__))) #define TRACE kprintf("%s()\n", __FUNCTION__) #define TRACEMSG(msg,...) kprintf("%s(): " msg "\n", __FUNCTION__, ## __VA_ARGS__) @@ -307,7 +310,13 @@ INLINE void kdbg_init(void) { /* nop */ } INLINE void kputchar(UNUSED(char, c)) { /* nop */ } INLINE void kputs(UNUSED(const char*, str)) { /* nop */ } - INLINE void kprintf(UNUSED(const char*, fmt), ...) { /* nop */ } + #ifdef __cplusplus + /* G++ can't inline functions with variable arguments... */ + #define kprintf(fmt,...) do { (void)(fmt); } while(0) + #else + /* ...but GCC can. */ + INLINE void kprintf(UNUSED(const char*, fmt), ...) { /* nop */ } + #endif #endif /* _DEBUG */ diff --git a/drv/eeprom.c b/drv/eeprom.c index 34666aaf..81b29588 100755 --- a/drv/eeprom.c +++ b/drv/eeprom.c @@ -5,18 +5,20 @@ * All Rights Reserved. * --> * - * \version $Id$ - * - * \author Stefano Fedrigo - * \author Bernardo Innocenti - * * \brief Driver for the 24xx16 and 24xx256 I2C EEPROMS (implementation) * * \note This implementation is AVR specific. + * + * \version $Id$ + * \author Stefano Fedrigo + * \author Bernardo Innocenti */ /*#* *#* $Log$ + *#* Revision 1.10 2004/09/20 03:31:22 bernie + *#* Sanitize for C++. + *#* *#* Revision 1.9 2004/09/14 21:03:46 bernie *#* Use debug.h instead of kdebug.h. *#* @@ -160,8 +162,10 @@ static void twi_stop(void) * * \return true on success, false on error. */ -static bool twi_send(const uint8_t *buf, size_t count) +static bool twi_send(const void *_buf, size_t count) { + const uint8_t *buf = (const uint8_t *)_buf; + while (count--) { TWDR = *buf++; @@ -187,8 +191,10 @@ static bool twi_send(const uint8_t *buf, size_t count) * * \return true on success, false on error */ -static bool twi_recv(uint8_t *buf, size_t count) +static bool twi_recv(void *_buf, size_t count) { + uint8_t *buf = (uint8_t *)_buf; + /* * When reading the last byte the TWEA bit is not * set, and the eeprom should answer with NACK @@ -411,8 +417,8 @@ void eeprom_init(void) void eeprom_test(void) { - static const char magic[13] = "Humpty Dumpty"; - char buf[sizeof magic + 1]; + static const char magic[14] = "Humpty Dumpty"; + char buf[sizeof magic]; size_t i; // Write something to EEPROM using unaligned sequential writes diff --git a/drv/ser.c b/drv/ser.c index 35a4d192..289551d0 100755 --- a/drv/ser.c +++ b/drv/ser.c @@ -28,6 +28,9 @@ /*#* *#* $Log$ + *#* Revision 1.18 2004/09/20 03:31:15 bernie + *#* Sanitize for C++. + *#* *#* Revision 1.17 2004/09/14 21:06:07 bernie *#* Use debug.h instead of kdebug.h; Spelling fixes. *#* @@ -304,7 +307,7 @@ int ser_print(struct Serial *port, const char *s) */ int ser_write(struct Serial *port, const void *_buf, size_t len) { - const char *buf = _buf; + const char *buf = (const char *)_buf; while (len--) {