Skip to main content
valentin
Associate III
May 2, 2017
Solved

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

  • May 2, 2017
  • 4 replies
  • 1820 views
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
    This topic has been closed for replies.
    Best answer by Jeroen3
    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.

    4 replies

    ST Technical Moderator
    May 3, 2017
    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

    In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Thanks
    Jeroen3
    Jeroen3Best answer
    Senior
    May 4, 2017
    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.

    valentin
    valentinAuthor
    Associate III
    May 4, 2017
    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 ...

    Jeroen3
    Senior
    May 5, 2017
    Posted on May 05, 2017 at 15:46

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