Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. Treat warnings as errors ?

Treat warnings as errors ?

Scheduled Pinned Locked Moved The Lounge
question
42 Posts 26 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Tom Deketelaere

    I turn it on when possible (sometimes you can't avoid getting the warning), I try to watch out for them since I have experianced 'bugs' because off them

    G Offline
    G Offline
    Graham Bradshaw
    wrote on last edited by
    #8

    TDDragon wrote:

    I turn it on when possible (sometimes you can't avoid getting the warning),

    That's what #pragma warning(push/pop) and #pragma warning(disable: x) are for, so you can turn off a specific warning for a short section of code.

    C T 2 Replies Last reply
    0
    • G Graham Bradshaw

      TDDragon wrote:

      I turn it on when possible (sometimes you can't avoid getting the warning),

      That's what #pragma warning(push/pop) and #pragma warning(disable: x) are for, so you can turn off a specific warning for a short section of code.

      C Offline
      C Offline
      Christian Flutcher
      wrote on last edited by
      #9

      Graham Bradshaw wrote:

      #pragma warning(push/pop) and #pragma warning(disable: x)

      WOW ! That's great. I will look into that. Thanks

      1 Reply Last reply
      0
      • C Christian Flutcher

        Do you used to turn it on ? I always plan to do so, but the number of warnings will force me to turn it off again. I would like to know is it worth turning that option "on" ?

        V Offline
        V Offline
        V 0
        wrote on last edited by
        #10

        You could leave the option to "off" and make a habit in checking the warnings ;-)

        V.
        Stop smoking so you can: Enjoy longer the money you save. Moviereview Archive

        1 Reply Last reply
        0
        • C Christian Flutcher

          Do you used to turn it on ? I always plan to do so, but the number of warnings will force me to turn it off again. I would like to know is it worth turning that option "on" ?

          M Offline
          M Offline
          Mike Diack
          wrote on last edited by
          #11

          I can't speak for others, but I personally always do. I do know that sometimes (especially VC6's STL code), library headers etc produce warnings, but I always think it's worth wrapping #pragma's around such situations to disable the warnings. Having code compile clean with /W4 /WX is a very useful baseline, potential breakage is instantly spotted. I have to admit I take it further as well by using Gimpel's PC Lint and Microsoft's own C++ static analysis (/analyze) tools in VC 2005 and later. Mike

          A 1 Reply Last reply
          0
          • C Christian Flutcher

            Yeah. Most of them are unused variable warnings. Actually it's a maintenance project, so hard to fix all those warnings.

            C Offline
            C Offline
            Cedric Moonen
            wrote on last edited by
            #12

            ForumExpertOnLine wrote:

            Most of them are unused variable warnings

            Why don't you just remove those unused variables then ? If it is an argument of one of your function and you can't remove it (e.g. virtual function), do not name it:

            void MyFunction(int)
            {
            // Code here
            }

            Cédric Moonen Software developer
            Charting control [v1.4] OpenGL game tutorial in C++

            G E G B R 5 Replies Last reply
            0
            • G Graham Bradshaw

              TDDragon wrote:

              I turn it on when possible (sometimes you can't avoid getting the warning),

              That's what #pragma warning(push/pop) and #pragma warning(disable: x) are for, so you can turn off a specific warning for a short section of code.

              T Offline
              T Offline
              Tom Deketelaere
              wrote on last edited by
              #13

              true but that's c# only I have to work in vb.net and unless I'm mistaking there is no such a 'code' in vb.net I could alter the project file as explaned here: http://www.helixoft.com/blog/archives/31[^] but then I'd rather leave them as warnings and check (and correct them if possible) them whenever one pops up

              G 1 Reply Last reply
              0
              • C Cedric Moonen

                ForumExpertOnLine wrote:

                Most of them are unused variable warnings

                Why don't you just remove those unused variables then ? If it is an argument of one of your function and you can't remove it (e.g. virtual function), do not name it:

                void MyFunction(int)
                {
                // Code here
                }

                Cédric Moonen Software developer
                Charting control [v1.4] OpenGL game tutorial in C++

                G Offline
                G Offline
                Graham Bradshaw
                wrote on last edited by
                #14

                I always prefer

                void MyFunction(int param)
                {
                // Code here

                UNREFEERENCED_PARAMETER(param);
                }

                To me, that says "I made a conscious decision to ignore the variable", rather than "I forgot to use it". You also get to keep the name of the variable, which (you would hope) would include some semantic information in the name itself.

                1 Reply Last reply
                0
                • T Tom Deketelaere

                  true but that's c# only I have to work in vb.net and unless I'm mistaking there is no such a 'code' in vb.net I could alter the project file as explaned here: http://www.helixoft.com/blog/archives/31[^] but then I'd rather leave them as warnings and check (and correct them if possible) them whenever one pops up

                  G Offline
                  G Offline
                  Graham Bradshaw
                  wrote on last edited by
                  #15

                  TDDragon wrote:

                  that's c# only

                  and C++

                  T 1 Reply Last reply
                  0
                  • G Graham Bradshaw

                    TDDragon wrote:

                    that's c# only

                    and C++

                    T Offline
                    T Offline
                    Tom Deketelaere
                    wrote on last edited by
                    #16

                    Yeah sorry forgot about that one ;P its been over 3 years since I done anything in C++ so I'm a bit rusty on that language (really should look into it again)

                    1 Reply Last reply
                    0
                    • C Cedric Moonen

                      ForumExpertOnLine wrote:

                      Most of them are unused variable warnings

                      Why don't you just remove those unused variables then ? If it is an argument of one of your function and you can't remove it (e.g. virtual function), do not name it:

                      void MyFunction(int)
                      {
                      // Code here
                      }

                      Cédric Moonen Software developer
                      Charting control [v1.4] OpenGL game tutorial in C++

                      E Offline
                      E Offline
                      Emilio Garavaglia
                      wrote on last edited by
                      #17

                      Nice, and what about HFONT CreateFont(int,int,int,int,int,int,int,int,int,int,int,int,int,LPCTSTR); at least names suggest something more about the possible usage (!)

                      2 bugs found. > recompile ... 65534 bugs found. :doh:

                      C 1 Reply Last reply
                      0
                      • C Christian Flutcher

                        Do you used to turn it on ? I always plan to do so, but the number of warnings will force me to turn it off again. I would like to know is it worth turning that option "on" ?

                        S Offline
                        S Offline
                        swjam
                        wrote on last edited by
                        #18

                        Compilers don't warn The Chuck Norris, The Chuch Norris warns them. If compilers don't fix the errors themselves, The Chuch Norris round house kicks them to 0xC0000005.

                        ---------------------------------------------------------- Every nation state's armed forces call themselves 'Defence', makes me wonder why there are conflicts in the world.

                        1 Reply Last reply
                        0
                        • C Christian Flutcher

                          Do you used to turn it on ? I always plan to do so, but the number of warnings will force me to turn it off again. I would like to know is it worth turning that option "on" ?

                          H Offline
                          H Offline
                          hairy_hats
                          wrote on last edited by
                          #19

                          No I don't, but then the only errors I get are VC6 STL warnings on the length of the names. Well, those are the only ones I get at level 3, at level 4 there are lots but it's a legacy project which is too big to sort out. :(

                          J 1 Reply Last reply
                          0
                          • C Cedric Moonen

                            ForumExpertOnLine wrote:

                            Most of them are unused variable warnings

                            Why don't you just remove those unused variables then ? If it is an argument of one of your function and you can't remove it (e.g. virtual function), do not name it:

                            void MyFunction(int)
                            {
                            // Code here
                            }

                            Cédric Moonen Software developer
                            Charting control [v1.4] OpenGL game tutorial in C++

                            G Offline
                            G Offline
                            Gary Wheeler
                            wrote on last edited by
                            #20

                            I prefer:

                            void MyFunction(int /*my_arg*/)
                            {
                            // Code here
                            }

                            Software Zen: delete this;

                            1 Reply Last reply
                            0
                            • C Cedric Moonen

                              ForumExpertOnLine wrote:

                              Most of them are unused variable warnings

                              Why don't you just remove those unused variables then ? If it is an argument of one of your function and you can't remove it (e.g. virtual function), do not name it:

                              void MyFunction(int)
                              {
                              // Code here
                              }

                              Cédric Moonen Software developer
                              Charting control [v1.4] OpenGL game tutorial in C++

                              B Offline
                              B Offline
                              benjymous
                              wrote on last edited by
                              #21

                              void MyFunction(int /*iMyValue*/)
                              {
                              // Code here
                              }

                              at least reminds you what the variable name was

                              Help me! I'm turning into a grapefruit! Buzzwords!

                              1 Reply Last reply
                              0
                              • C Christian Flutcher

                                Do you used to turn it on ? I always plan to do so, but the number of warnings will force me to turn it off again. I would like to know is it worth turning that option "on" ?

                                A Offline
                                A Offline
                                Anna Jayne Metcalfe
                                wrote on last edited by
                                #22

                                We try not to have warnings (or lint issues for that matter) in our code in the first place. When they creep in (which will inevitably happen, especially during major changes), they are removed shortly afterwards. However, in my experience "Treat warnings as errors" is a great way to annoy your teammates - especically if they are less meticulous in fixing warnings.

                                Anna :rose: Having a bad bug day? Anna's Place | Tears and Laughter "If mushy peas are the food of the devil, the stotty cake is the frisbee of God"

                                1 Reply Last reply
                                0
                                • E Emilio Garavaglia

                                  Nice, and what about HFONT CreateFont(int,int,int,int,int,int,int,int,int,int,int,int,int,LPCTSTR); at least names suggest something more about the possible usage (!)

                                  2 bugs found. > recompile ... 65534 bugs found. :doh:

                                  C Offline
                                  C Offline
                                  Cedric Moonen
                                  wrote on last edited by
                                  #23

                                  emilio_grv wrote:

                                  Nice, and what about HFONT CreateFont(int,int,int,int,int,int,int,int,int,int,int,int,int,LPCTSTR); at least names suggest something more about the possible usage (!)

                                  Some remarks: 1) the problem occurs when you define your own function with some parameters and do not use all of them inside your function. Suppose that you want to provide a global CreateFont function, then it doesn't make any sense at all to provide so many parameters but not use a single one inside the CreateFont function. It seems wrong to me, because the user can provide whatever parameters, the function will not use them. So why do you need to provide them ? 2) There are some cases where you can't avoid that: like for example you have a virtual function in a base class that you want to specialize in the child class but do not use all parameters in the function. In that case, your parameters are still named in the prototype declared in the base class. 3) Nothing prevents you to give a name to the parameter in the function prototype but no name in the function definition. But I agree, the other propositions also make sense (using the UNREFERECED_PARAMETER macro or commenting their names).

                                  Cédric Moonen Software developer
                                  Charting control [v1.4] OpenGL game tutorial in C++

                                  1 Reply Last reply
                                  0
                                  • M Mike Diack

                                    I can't speak for others, but I personally always do. I do know that sometimes (especially VC6's STL code), library headers etc produce warnings, but I always think it's worth wrapping #pragma's around such situations to disable the warnings. Having code compile clean with /W4 /WX is a very useful baseline, potential breakage is instantly spotted. I have to admit I take it further as well by using Gimpel's PC Lint and Microsoft's own C++ static analysis (/analyze) tools in VC 2005 and later. Mike

                                    A Offline
                                    A Offline
                                    Anna Jayne Metcalfe
                                    wrote on last edited by
                                    #24

                                    Hello Mike - fancy bumping into you here! :laugh:

                                    Anna :rose: Having a bad bug day? Anna's Place | Tears and Laughter "If mushy peas are the food of the devil, the stotty cake is the frisbee of God"

                                    1 Reply Last reply
                                    0
                                    • C Christian Flutcher

                                      Do you used to turn it on ? I always plan to do so, but the number of warnings will force me to turn it off again. I would like to know is it worth turning that option "on" ?

                                      F Offline
                                      F Offline
                                      Franc Morales
                                      wrote on last edited by
                                      #25

                                      I always use "warning level 4" and I always deal with all warnings.. "treat warnings as errors" is not necessary. In fact, "treat warnings as errors" is a pain since it would stop builds when I want to postpone, for example, deleting an unused variable. I would say that using "warning level 4" is far more important than using "treat warnings as errors".

                                      1 Reply Last reply
                                      0
                                      • C Christian Flutcher

                                        Do you used to turn it on ? I always plan to do so, but the number of warnings will force me to turn it off again. I would like to know is it worth turning that option "on" ?

                                        E Offline
                                        E Offline
                                        Ennis Ray Lynch Jr
                                        wrote on last edited by
                                        #26

                                        When I am working as a lone developer absolutely. However, when I am part of a large team there are just too many monkeys running around claiming to write code. While my individual code will compile without warnings I just don't have the time or patience to fix the logical fallacies of other developers.

                                        Need a C# Consultant? I'm available.
                                        Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway

                                        1 Reply Last reply
                                        0
                                        • H hairy_hats

                                          No I don't, but then the only errors I get are VC6 STL warnings on the length of the names. Well, those are the only ones I get at level 3, at level 4 there are lots but it's a legacy project which is too big to sort out. :(

                                          J Offline
                                          J Offline
                                          John M Drescher
                                          wrote on last edited by
                                          #27

                                          Take a look at this: http://www.bdsoft.com/tools/stlfilt.html[^] I use that to nuke those darn (useless) length too long warnings.

                                          John

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups