cancel
Showing results for 
Search instead for 
Did you mean: 

[Suggestion] add __attribute__((unused)) to unused parameters in all library functions

valentin
Senior
Posted on May 03, 2017 at 01:36

When compiling projects using standard HAL libraries, I often get a dozen or so warnings about unused parameters in library functions.

Would it be possible to tell your programmers to please add '__attribute__((unused))' in front of all unused parameters or unused variables in general?

Right now my only solution is to completely disable all warnings for the 'Middlewares' and 'Drivers' folders which is not really helpful.

Examples:

usbd_desc.c:

uint8_t * USBD_HS_ManufacturerStrDescriptor(__attribute__((unused)) USBD_SpeedTypeDef speed , uint16_t *length)
{
 USBD_GetString ((uint8_t *)USBD_MANUFACTURER_STRING, USBD_StrDesc, length);
 return USBD_StrDesc;
}�?�?�?�?�?
uint8_t * USBD_HS_LangIDStrDescriptor( __attribute__((unused)) USBD_SpeedTypeDef speed , uint16_t *length)
{
 *length = sizeof(USBD_LangIDDesc); 
 return USBD_LangIDDesc;
}�?�?�?�?�?

Compiling a sample project with some extra warning flags enabled should give a very quick & easy way to find all relevant lines.

Thank you!

#warnings #attrib_unused
1 ACCEPTED SOLUTION

Accepted Solutions
Jeroen3
Senior
Posted on May 04, 2017 at 11:47

No. Don't add compiler specific attributes. Use this instead:

int foo(int unused){
 (void)unused;
}�?�?�?�?�?�?

Or just suppress the warning. This you can to with #pragma per file, per compiler.

View solution in original post

4 REPLIES 4
Imen.D
ST Employee
Posted on May 03, 2017 at 10:48

Hi,

Thank you for your suggestion to improve our solutions.

I will share this internally for further investigation and keep you informed about the taken actions/explanation if needed.

Thanks

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen
Jeroen3
Senior
Posted on May 04, 2017 at 11:47

No. Don't add compiler specific attributes. Use this instead:

int foo(int unused){
 (void)unused;
}�?�?�?�?�?�?

Or just suppress the warning. This you can to with #pragma per file, per compiler.

Posted on May 04, 2017 at 22:11

even better!

edit: although with that solution I'm now getting 'statement has no effect [-Wunused-value]' warnings ...

Posted on May 05, 2017 at 15:46

You have waaay to much warnings enabled. This is not default behavior.