From b196a4a9c547a76b460aaeeb7c963ca7a13d41ef Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Tue, 18 Feb 2014 21:00:32 +0100 Subject: [PATCH] Suppress "unused parameter" warnings A bunch of functions have parameters they do not use, but which cannot be removed for API compatibility. In syscalls_sam3.c, there are a lot of these, so this adds an "UNUSED" macro which adds the "unused" variable attribute if supported (GCC specific), or is just a noop on other compilers. In CDC.cpp, there's only three of these variables, so this commit just forces a dummy evaluation of them to suppress the warnings. This helps towards #1792. --- .../arduino/sam/cores/arduino/USB/CDC.cpp | 5 ++++ .../arduino/sam/cores/arduino/syscalls_sam3.c | 24 ++++++++++++------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/hardware/arduino/sam/cores/arduino/USB/CDC.cpp b/hardware/arduino/sam/cores/arduino/USB/CDC.cpp index 84a4e9132..4d646e723 100644 --- a/hardware/arduino/sam/cores/arduino/USB/CDC.cpp +++ b/hardware/arduino/sam/cores/arduino/USB/CDC.cpp @@ -147,10 +147,15 @@ bool WEAK CDC_Setup(Setup& setup) int _serialPeek = -1; void Serial_::begin(uint32_t baud_count) { + // suppress "unused parameter" warning + (void)baud_count; } void Serial_::begin(uint32_t baud_count, uint8_t config) { + // suppress "unused parameter" warning + (void)baud_count; + (void)config; } void Serial_::end(void) diff --git a/hardware/arduino/sam/cores/arduino/syscalls_sam3.c b/hardware/arduino/sam/cores/arduino/syscalls_sam3.c index 23256db6d..3ea76659c 100644 --- a/hardware/arduino/sam/cores/arduino/syscalls_sam3.c +++ b/hardware/arduino/sam/cores/arduino/syscalls_sam3.c @@ -38,6 +38,14 @@ #include #endif +// Helper macro to mark unused parameters and prevent compiler warnings. +// Appends _UNUSED to the variable name to prevent accidentally using them. +#ifdef __GNUC__ +# define UNUSED(x) x ## _UNUSED __attribute__((__unused__)) +#else +# define UNUSED(x) x ## _UNUSED +#endif + /*---------------------------------------------------------------------------- * Exported variables *----------------------------------------------------------------------------*/ @@ -69,39 +77,39 @@ extern caddr_t _sbrk ( int incr ) return (caddr_t) prev_heap ; } -extern int link( char *cOld, char *cNew ) +extern int link( UNUSED(char *cOld), UNUSED(char *cNew) ) { return -1 ; } -extern int _close( int file ) +extern int _close( UNUSED(int file) ) { return -1 ; } -extern int _fstat( int file, struct stat *st ) +extern int _fstat( UNUSED(int file), struct stat *st ) { st->st_mode = S_IFCHR ; return 0 ; } -extern int _isatty( int file ) +extern int _isatty( UNUSED(int file) ) { return 1 ; } -extern int _lseek( int file, int ptr, int dir ) +extern int _lseek( UNUSED(int file), UNUSED(int ptr), UNUSED(int dir) ) { return 0 ; } -extern int _read(int file, char *ptr, int len) +extern int _read(UNUSED(int file), UNUSED(char *ptr), UNUSED(int len) ) { return 0 ; } -extern int _write( int file, char *ptr, int len ) +extern int _write( UNUSED(int file), char *ptr, int len ) { int iIndex ; @@ -129,7 +137,7 @@ extern void _exit( int status ) for ( ; ; ) ; } -extern void _kill( int pid, int sig ) +extern void _kill( UNUSED(int pid), UNUSED(int sig) ) { return ; }