0

Why on sololearn cpp compiler returns unsused variable in for (auto i : arr)?

I made some code which generates weird warnings, why? This code runs without warnings at for example tutorialspoint compiler Code: https://code.sololearn.com/ceO0NP95v7W4/?ref=app

26th Aug 2021, 4:02 PM
nicolas turek
nicolas turek - avatar
6 Réponses
+ 1
nicolas turek you are getting error "unused variable i "here which you said you aren't getting on tutorials point. The above link should be enough to answer why is it happening . Assuming the compiler is gcc it doesn't prints out the error by default but can be configured to do so. It's the same for clang++ as i just tested.
26th Aug 2021, 5:05 PM
Abhay
Abhay - avatar
+ 1
Following is the answer that i am pointing to . The first 5 lines should be enough to understand the reason behind it . "gcc doesn't flag these warnings by defaqult. This warning must have been turned on either explicitly by passing -Wunused-parameter to the compiler or implicitly by passing -Wall -Wextra (or possibly some other combination of flags). Unused parameter warnings can simply be suppressed by passing -Wno-unused-parameter to the compiler, but note that this disabling flag must come after any possible enabling flags for this warning in the compiler command line, so that it can take effect." But if it doesn't helps then i am sorry . Maybe i just can't understand what you are looking for .
26th Aug 2021, 5:19 PM
Abhay
Abhay - avatar
+ 1
Seems like it could be answer, thanks, by this I gues sololearn compiler just makes these warnings on purpose to anoy us
26th Aug 2021, 5:28 PM
nicolas turek
nicolas turek - avatar
0
This is more like how to hide it, which I'm not asking for, I'd like to know why it does return warning for iterator (which is quite used)
26th Aug 2021, 4:53 PM
nicolas turek
nicolas turek - avatar
0
I can't find the answer there, it's kind of messy, by many duplicite answers about using macro, and what I counted to be 8th is just solution
26th Aug 2021, 5:15 PM
nicolas turek
nicolas turek - avatar