Menu

Why no warnings for unused variables?

2003-12-20
2012-09-26
  • Øyvind Kaurstad

    I have always been fond of getting warnings for unused variables, since I sometimes forget to remove them manually when I change the code.

    By default, Dev-C++ does not turn these warnings on, but I think that there should be an explicit option to turn this on. Adding -Wunused-variable to the compiler options from within Dev works like a charm, but I think that for newbies it should be turned on by default.

    One could argue that unused variables pose no risk, and that is probably correct, but...

     
    • Anonymous

      Anonymous - 2003-12-20

      Use the following compiler option:

      -Wall

      I would also recommend -Werror, and -Wformat. (because '-Wall' does not quite mean 'all').

      Check the warning options here:http://gcc.gnu.org/onlinedocs/gcc-3.2.3/gcc/Warning-Options.html#Warning%20Options

      If you add these options to the compiler options under Tools|Compiler options., thet will applied to all subsequently created projects (like a  default). For existing projects you will have to add them manually to the project options.

      Clifford.

       
    • Kip

      Kip - 2003-12-20

      "because '-Wall' does not quite mean 'all'"

      Actually it does =)

      Kip

       
      • qWake

        qWake - 2003-12-20

        It doesn't according to the documentation given from that link.  Read the section that starts with "The following -W... options are not implied by -Wall"

        qWake

         
        • Øyvind Kaurstad

          But -Wformat seems to be implied with -Wall, despite what Clifford said.

          -Werror is not implied by -Wall, however. I don't think I want that one, though. I will always clean off all warnings at the end anyway, so converting them to errors makes no sense to me.

          The original question still remains, though:

          Why doesn't Dev-C++ have any of these options as the default? There is a checkbox to inhibit warnings, but no chekbox to add them. By default Dev-C++ doesn't give many warnings.

           
          • Anonymous

            Anonymous - 2003-12-20

            In a large project (I typically deal with several hundred sourcefiles), especially when working in a team, it is easy not to spot warnings amongst the compiler output. That is why I use -Werror. Also often warnings are indicitive of actual errors, so you may as well stop and fix them anyway. It also improves your coding style, after a while you write code that is just correct in the first place.

            Clifford.

             
            • Wayne Keen

              Wayne Keen - 2003-12-20

              This is one of those topics that can get religous and bellicose in short order.

              It is interesting that it is also one of those areas where two people can look at the same data and come to opposite conclusions.  The demographics (*I* think) for Dev-C++ skew towards the very new programmer.  Evidence suggests many of them do not even understand the difference between a warning and an error, and many used to freak when a warning was generated about deprecated headers, so, you could say

              (1) Making them fix warnings is a good thing, gets them started right

              (2)  Warnings scare off new folks who otherwise, once they get their feet on the ground, would program just fine

              Both have some merit...

              Wayne

               
              • Nobody/Anonymous

                Further to what Wayne says above, when I learnt C (and also when learning C++) I found:

                -wall -ansi -pedantic

                To be very useful in terms of making me *really* think about my code.  (My aim being to learn something I could use with any compiler[1])

                Iain

                [1]  At that point I'd not considered that not all compilers would adhere to the standards.

                 
              • Kip

                Kip - 2003-12-22

                Wayne, you are really cool when you speak in earnest, like here, instead of apple juiced.

                Kip

                 
                • Wayne Keen

                  Wayne Keen - 2003-12-22

                  I hate apple jiuce!

                  Wayne

                   

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.