Wie man zum Schweigen bringt -wung -variable auf volatilen Werten
Posted: 18 May 2025, 20:51
In C ++ können Sie eine nicht verwendete variable Warnung zum Parameter vermeiden, indem Sie den Namen weglassen. oder (void) ). IT ": < /p>
für gcc" wie "compiler: < /p>
@Davis-Herring (funktioniert nicht wie so, aber kann mit std :: adressof gearbeitet werden. />
Siehe https://godbolt.org/z/cyvxqm3hq
Code: Select all
static_cast(x)
für gcc" wie "compiler: < /p>
- (für c ++)
Code: Select all
[[gnu::unused]]
- (für c/c ++)
Code: Select all
__attribute__((unused))
Code: Select all
std::ignore = ;< /code> < /li>
< /ul>
Für C ++ 17: < /p>
[[maybe_unused]]< /code> < /li>
< /ul>
Eine Lösung in C oder C ++: < /p>
(void)sizeof aze;
Code: Select all
// compile with gcc -O3 -Wall -wextra
void test() {
int volatile aze = 0;
(void)aze;
}
< /code>
test:
mov DWORD PTR [rsp-4], 0
mov eax, DWORD PTR [rsp-4]
ret