Skip to content

Commit b9add17

Browse files
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 arduino#1792.
1 parent 56bebbb commit b9add17

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

cores/arduino/USB/CDC.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,15 @@ bool WEAK CDC_Setup(Setup& setup)
147147
int _serialPeek = -1;
148148
void Serial_::begin(uint32_t baud_count)
149149
{
150+
// suppress "unused parameter" warning
151+
(void)baud_count;
150152
}
151153

152154
void Serial_::begin(uint32_t baud_count, uint8_t config)
153155
{
156+
// suppress "unused parameter" warning
157+
(void)baud_count;
158+
(void)config;
154159
}
155160

156161
void Serial_::end(void)

cores/arduino/syscalls_sam3.c

+16-8
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@
3838
#include <sys/stat.h>
3939
#endif
4040

41+
// Helper macro to mark unused parameters and prevent compiler warnings.
42+
// Appends _UNUSED to the variable name to prevent accidentally using them.
43+
#ifdef __GNUC__
44+
# define UNUSED(x) x ## _UNUSED __attribute__((__unused__))
45+
#else
46+
# define UNUSED(x) x ## _UNUSED
47+
#endif
48+
4149
/*----------------------------------------------------------------------------
4250
* Exported variables
4351
*----------------------------------------------------------------------------*/
@@ -69,39 +77,39 @@ extern caddr_t _sbrk ( int incr )
6977
return (caddr_t) prev_heap ;
7078
}
7179

72-
extern int link( char *cOld, char *cNew )
80+
extern int link( UNUSED(char *cOld), UNUSED(char *cNew) )
7381
{
7482
return -1 ;
7583
}
7684

77-
extern int _close( int file )
85+
extern int _close( UNUSED(int file) )
7886
{
7987
return -1 ;
8088
}
8189

82-
extern int _fstat( int file, struct stat *st )
90+
extern int _fstat( UNUSED(int file), struct stat *st )
8391
{
8492
st->st_mode = S_IFCHR ;
8593

8694
return 0 ;
8795
}
8896

89-
extern int _isatty( int file )
97+
extern int _isatty( UNUSED(int file) )
9098
{
9199
return 1 ;
92100
}
93101

94-
extern int _lseek( int file, int ptr, int dir )
102+
extern int _lseek( UNUSED(int file), UNUSED(int ptr), UNUSED(int dir) )
95103
{
96104
return 0 ;
97105
}
98106

99-
extern int _read(int file, char *ptr, int len)
107+
extern int _read(UNUSED(int file), UNUSED(char *ptr), UNUSED(int len) )
100108
{
101109
return 0 ;
102110
}
103111

104-
extern int _write( int file, char *ptr, int len )
112+
extern int _write( UNUSED(int file), char *ptr, int len )
105113
{
106114
int iIndex ;
107115

@@ -129,7 +137,7 @@ extern void _exit( int status )
129137
for ( ; ; ) ;
130138
}
131139

132-
extern void _kill( int pid, int sig )
140+
extern void _kill( UNUSED(int pid), UNUSED(int sig) )
133141
{
134142
return ;
135143
}

0 commit comments

Comments
 (0)