1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-01-30 19:52:13 +01:00

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.
This commit is contained in:
Matthijs Kooijman 2014-02-18 21:00:32 +01:00
parent 4cf21dcdd1
commit b196a4a9c5
2 changed files with 21 additions and 8 deletions

View File

@ -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)

View File

@ -38,6 +38,14 @@
#include <sys/stat.h>
#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 ;
}