Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to remove incorrect warning?
Forum Updated to NodeBB v4.3 + New Features

How to remove incorrect warning?

Scheduled Pinned Locked Moved Solved General and Desktop
29 Posts 6 Posters 6.0k Views 3 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.
  • EngelardE Offline
    EngelardE Offline
    Engelard
    wrote on last edited by
    #17
    This post is deleted!
    kshegunovK 1 Reply Last reply
    -1
    • EngelardE Engelard

      This post is deleted!

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by
      #18

      I can guarantee you you're never going to enter that branch. You're playing with fire. See my previous comment.

      Read and abide by the Qt Code of Conduct

      1 Reply Last reply
      0
      • kshegunovK kshegunov

        Your code is wrong, so that warning is very useful in fact.

        if (exitCode != reinterpret_cast<LPCVOID>(...))
        

        is nonsense. You can't (or rather shouldn't) cast integers to const void * ...
        What you should do instead is something like this:

        if (*exitCode != STILL_ACTIVE) { /* do something */ }
        

        reinterpret_cast is the one sure way to blow your leg off while trying to shoot yourself in the foot.

        EngelardE Offline
        EngelardE Offline
        Engelard
        wrote on last edited by
        #19

        @kshegunov said in How to remove incorrect warning?:

        What you should do instead is something like this:
        if (exitCode != STILL_ACTIVE) { / do something */ }

        Nope

        Will be more warnings(first one actually, no matter what code you'll make, it screaming because of definition inside windows libraries). Your proposal:
        0_1543868290472_hhhhh.jpg

        kshegunovK 1 Reply Last reply
        0
        • EngelardE Engelard

          @kshegunov said in How to remove incorrect warning?:

          What you should do instead is something like this:
          if (exitCode != STILL_ACTIVE) { / do something */ }

          Nope

          Will be more warnings(first one actually, no matter what code you'll make, it screaming because of definition inside windows libraries). Your proposal:
          0_1543868290472_hhhhh.jpg

          kshegunovK Offline
          kshegunovK Offline
          kshegunov
          Moderators
          wrote on last edited by
          #20

          Don't make me smack you; I've been doing programming all my life.

          Firstly, the warning is the least of your problems. You're giving a pointer to uninitialized memory block (i.e. null) as an output parameter. Then you're casting an integer to a memory address?
          How it works is as follows:

          DWORD exitCode;
          GetExitProces(..., &exitCode);
          if (exitCode != STILL_ACTIVE)  { /* blabla */ }
          

          If the warning is the only thing that bothers you, then cast the macro to the proper type explicitly:

          if (exitCode != static_cast<DWORD>(STILL_ACTIVE))  { /* more blabla */ }
          

          Read and abide by the Qt Code of Conduct

          EngelardE 1 Reply Last reply
          1
          • kshegunovK kshegunov

            Don't make me smack you; I've been doing programming all my life.

            Firstly, the warning is the least of your problems. You're giving a pointer to uninitialized memory block (i.e. null) as an output parameter. Then you're casting an integer to a memory address?
            How it works is as follows:

            DWORD exitCode;
            GetExitProces(..., &exitCode);
            if (exitCode != STILL_ACTIVE)  { /* blabla */ }
            

            If the warning is the only thing that bothers you, then cast the macro to the proper type explicitly:

            if (exitCode != static_cast<DWORD>(STILL_ACTIVE))  { /* more blabla */ }
            
            EngelardE Offline
            EngelardE Offline
            Engelard
            wrote on last edited by
            #21

            @kshegunov said in How to remove incorrect warning?:

            If the warning is the only thing that bothers you, then cast the macro to the proper type explicitly:
            if (exitCode != static_cast<DWORD>(STILL_ACTIVE)) { /* more blabla */ }

            1. For last time. Yes, it's just was almost hundred in my app, now 0(if not mention that with STILL_ACTIVE).
            2. Your new example of static cast doing nothing, because in definition in win's.h it is already DWORD:

            0_1543869432495_stillwarning.jpg

            1 Reply Last reply
            0
            • JKSHJ Offline
              JKSHJ Offline
              JKSH
              Moderators
              wrote on last edited by JKSH
              #22

              First, @kshegunov is right -- The "solution" is wrong because LPDWORD is unsigned long *. Your marked "solution" is like this:

              unsigned long *exitCode = ...
              unsigned long *checkCode = ...
              if (exitCode != checkCode) { /*do stuff*/ }
              

              Do you see the problem with comparing pointers?

              Second, @Engelard is right -- The warning exists because of macros in the Windows headers:

              // minwinbase.h
              #define STILL_ACTIVE     STATUS_PENDING
              
              // winnt.h
              #define STATUS_PENDING   ((DWORD)0x00000103L) // Old-style cast here, not in user code
              

              There's no way to cast this away in user code.

              Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

              EngelardE kshegunovK 2 Replies Last reply
              2
              • JKSHJ JKSH

                First, @kshegunov is right -- The "solution" is wrong because LPDWORD is unsigned long *. Your marked "solution" is like this:

                unsigned long *exitCode = ...
                unsigned long *checkCode = ...
                if (exitCode != checkCode) { /*do stuff*/ }
                

                Do you see the problem with comparing pointers?

                Second, @Engelard is right -- The warning exists because of macros in the Windows headers:

                // minwinbase.h
                #define STILL_ACTIVE     STATUS_PENDING
                
                // winnt.h
                #define STATUS_PENDING   ((DWORD)0x00000103L) // Old-style cast here, not in user code
                

                There's no way to cast this away in user code.

                EngelardE Offline
                EngelardE Offline
                Engelard
                wrote on last edited by Engelard
                #23

                @JKSH said in How to remove incorrect warning?:

                The marked "solution" is like this:

                It's not a proper solution.You just changed my example from DWORD pointer (which most proper unsigned int when working with winApi functions) to pointer of quite same type.
                My solution with LPDWORD more correct simply because function GetExitCodeProcess demand LPDWORD. There was some reason why guys from microsoft put exactly that type as parameter, not LPVOID or LPCVOID. So i just used that what they recommend. Or they put such types instead simple unsigned ints just for fun?

                @JKSH said in How to remove incorrect warning?:

                There's no way to cast this away in user code.

                Ye. And even such casting i consider as not a solution at all.
                Proper solution to whole thing would be - remove single warning(not whole type of that warning, because that value(0x00000103L) even through autoExplicitCast will never cause any error/crush to any kind of app which using such things like predefined variables which never will change it's values.

                JKSHJ kshegunovK 2 Replies Last reply
                -1
                • EngelardE Engelard

                  @JKSH said in How to remove incorrect warning?:

                  The marked "solution" is like this:

                  It's not a proper solution.You just changed my example from DWORD pointer (which most proper unsigned int when working with winApi functions) to pointer of quite same type.
                  My solution with LPDWORD more correct simply because function GetExitCodeProcess demand LPDWORD. There was some reason why guys from microsoft put exactly that type as parameter, not LPVOID or LPCVOID. So i just used that what they recommend. Or they put such types instead simple unsigned ints just for fun?

                  @JKSH said in How to remove incorrect warning?:

                  There's no way to cast this away in user code.

                  Ye. And even such casting i consider as not a solution at all.
                  Proper solution to whole thing would be - remove single warning(not whole type of that warning, because that value(0x00000103L) even through autoExplicitCast will never cause any error/crush to any kind of app which using such things like predefined variables which never will change it's values.

                  JKSHJ Offline
                  JKSHJ Offline
                  JKSH
                  Moderators
                  wrote on last edited by JKSH
                  #24

                  @Engelard said in How to remove incorrect warning?:

                  My solution with LPDWORD more correct simply because function GetExitCodeProcess demand LPDWORD.

                  It is correct to pass an LPDWORD parameter into GetExitCodeProcess().

                  It is wrong to use == or != to compare two LPDWORD variables because it is wrong to use == or != to compare pointers. Do you agree?

                  Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                  EngelardE 1 Reply Last reply
                  1
                  • JKSHJ JKSH

                    First, @kshegunov is right -- The "solution" is wrong because LPDWORD is unsigned long *. Your marked "solution" is like this:

                    unsigned long *exitCode = ...
                    unsigned long *checkCode = ...
                    if (exitCode != checkCode) { /*do stuff*/ }
                    

                    Do you see the problem with comparing pointers?

                    Second, @Engelard is right -- The warning exists because of macros in the Windows headers:

                    // minwinbase.h
                    #define STILL_ACTIVE     STATUS_PENDING
                    
                    // winnt.h
                    #define STATUS_PENDING   ((DWORD)0x00000103L) // Old-style cast here, not in user code
                    

                    There's no way to cast this away in user code.

                    kshegunovK Offline
                    kshegunovK Offline
                    kshegunov
                    Moderators
                    wrote on last edited by
                    #25

                    @JKSH said in How to remove incorrect warning?:

                    Second, @Engelard is right -- The warning exists because of macros in the Windows headers

                    Indeed, I saw that, but decided that it's not worth continuing on with the argument if the code's wrong. I mean wanting to fix the clang warning is fine, but it's more important to fix the actual code.

                    Read and abide by the Qt Code of Conduct

                    1 Reply Last reply
                    0
                    • EngelardE Engelard

                      @JKSH said in How to remove incorrect warning?:

                      The marked "solution" is like this:

                      It's not a proper solution.You just changed my example from DWORD pointer (which most proper unsigned int when working with winApi functions) to pointer of quite same type.
                      My solution with LPDWORD more correct simply because function GetExitCodeProcess demand LPDWORD. There was some reason why guys from microsoft put exactly that type as parameter, not LPVOID or LPCVOID. So i just used that what they recommend. Or they put such types instead simple unsigned ints just for fun?

                      @JKSH said in How to remove incorrect warning?:

                      There's no way to cast this away in user code.

                      Ye. And even such casting i consider as not a solution at all.
                      Proper solution to whole thing would be - remove single warning(not whole type of that warning, because that value(0x00000103L) even through autoExplicitCast will never cause any error/crush to any kind of app which using such things like predefined variables which never will change it's values.

                      kshegunovK Offline
                      kshegunovK Offline
                      kshegunov
                      Moderators
                      wrote on last edited by kshegunov
                      #26

                      @Engelard said in How to remove incorrect warning?:

                      Or they put such types instead simple unsigned ints just for fun?

                      Well, no, they did it because that's how you return values in C (which is where the warning stems from as well). The header of the winapi is in C, and the clang parser expects C++ so it complains about things that are valid in C, but are bad style in C++. But as I said the warning is the least of your problems, fix your code.

                      Read and abide by the Qt Code of Conduct

                      1 Reply Last reply
                      2
                      • JKSHJ JKSH

                        @Engelard said in How to remove incorrect warning?:

                        My solution with LPDWORD more correct simply because function GetExitCodeProcess demand LPDWORD.

                        It is correct to pass an LPDWORD parameter into GetExitCodeProcess().

                        It is wrong to use == or != to compare two LPDWORD variables because it is wrong to use == or != to compare pointers. Do you agree?

                        EngelardE Offline
                        EngelardE Offline
                        Engelard
                        wrote on last edited by Engelard
                        #27

                        @JKSH said in How to remove incorrect warning?:

                        It is wrong to use == or != to compare two LPDWORD variables because it is wrong to use == or != to compare pointers. Do you agree?

                        Honestly, i don't know about comparing pointers, but it was in example to GetExitCodeProcess.

                        UPDATE:

                        Oh, now i get it. Was wrong example i found. So here is final code, do it better probably impossible:

                        0_1543934596938_gggggggggg.jpg

                        Tnx everyone for helping clarify those things.

                        JKSHJ 1 Reply Last reply
                        0
                        • EngelardE Engelard

                          @JKSH said in How to remove incorrect warning?:

                          It is wrong to use == or != to compare two LPDWORD variables because it is wrong to use == or != to compare pointers. Do you agree?

                          Honestly, i don't know about comparing pointers, but it was in example to GetExitCodeProcess.

                          UPDATE:

                          Oh, now i get it. Was wrong example i found. So here is final code, do it better probably impossible:

                          0_1543934596938_gggggggggg.jpg

                          Tnx everyone for helping clarify those things.

                          JKSHJ Offline
                          JKSHJ Offline
                          JKSH
                          Moderators
                          wrote on last edited by
                          #28

                          @Engelard said in How to remove incorrect warning?:

                          Oh, now i get it. Was wrong example i found. So here is final code

                          Good.

                          Do you understand the difference between the 2 sets of code that you posted?

                          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                          EngelardE 1 Reply Last reply
                          0
                          • JKSHJ JKSH

                            @Engelard said in How to remove incorrect warning?:

                            Oh, now i get it. Was wrong example i found. So here is final code

                            Good.

                            Do you understand the difference between the 2 sets of code that you posted?

                            EngelardE Offline
                            EngelardE Offline
                            Engelard
                            wrote on last edited by
                            #29

                            @JKSH said in How to remove incorrect warning?:

                            Do you understand the difference between the 2 sets of code that you posted?

                            Of course, as i tell above - first time encountered situation with comparing pointers, never thought before, about is it possible or not.

                            1 Reply Last reply
                            0

                            • Login

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • Users
                            • Groups
                            • Search
                            • Get Qt Extensions
                            • Unsolved