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. General Programming
  3. C / C++ / MFC
  4. Can Someone Explain Error Message

Can Someone Explain Error Message

Scheduled Pinned Locked Moved C / C++ / MFC
help
13 Posts 7 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.
  • S sweep123

    I get the following compile warning:- c:\TestProg\SigData.h(3625): warning C4146: unary minus operator applied to unsigned type, result still unsigned. I am assigning the value -2147483648 to an int field in a structure. Thanks.

    T Offline
    T Offline
    toxcct
    wrote on last edited by
    #2

    could you show the code that's crashing please ?


    TOXCCT >>> GEII power
    [toxcct][VisualCalc]

    S 1 Reply Last reply
    0
    • T toxcct

      could you show the code that's crashing please ?


      TOXCCT >>> GEII power
      [toxcct][VisualCalc]

      S Offline
      S Offline
      sweep123
      wrote on last edited by
      #3

      Sorry its just a compiler Warning, but was trying to get rid of it. I have a structure:- typedef struct { char scaling [SCALE_LENGTH]; char format [FORMAT_LEN]; char dataRaw [DATA_LEN]; char dataEng [DATA_LEN]; char display1 [DISPLAY_LEN]; int base; int offset; **int mask;** int wordSize; int shift; int noFieldsBefore; int noFieldsAfter; double maximum; double minimum; double fullScale; }SIGNAL_DETAILS; And init:- // Initialise Data Structure for the Signals SIGNAL_DETAILS signal_details[NO_FIELDS] = { "1", // Scaling "Integer", // Display Format "0", // Raw Data String "0", // Engineering Data String "%04X", // Raw Display Format 382, // Signal Memory Base 0, // Signal Memory Offset **-2147483648, // Signal Mask** 32, // Word Size 0, // Signal Shift 0, // Signal position in word - Before 3, // Signal position in word - After 255.000000 , // Signal Max Value 0.000000 , // Signal Min Value 255.000000 , // Signal Full Scale Value , // -------------------------------------------------- etc. Its the Initialisation of mask to -2147483648 that causes the problem.

      P R R J 4 Replies Last reply
      0
      • S sweep123

        Sorry its just a compiler Warning, but was trying to get rid of it. I have a structure:- typedef struct { char scaling [SCALE_LENGTH]; char format [FORMAT_LEN]; char dataRaw [DATA_LEN]; char dataEng [DATA_LEN]; char display1 [DISPLAY_LEN]; int base; int offset; **int mask;** int wordSize; int shift; int noFieldsBefore; int noFieldsAfter; double maximum; double minimum; double fullScale; }SIGNAL_DETAILS; And init:- // Initialise Data Structure for the Signals SIGNAL_DETAILS signal_details[NO_FIELDS] = { "1", // Scaling "Integer", // Display Format "0", // Raw Data String "0", // Engineering Data String "%04X", // Raw Display Format 382, // Signal Memory Base 0, // Signal Memory Offset **-2147483648, // Signal Mask** 32, // Word Size 0, // Signal Shift 0, // Signal position in word - Before 3, // Signal position in word - After 255.000000 , // Signal Max Value 0.000000 , // Signal Min Value 255.000000 , // Signal Full Scale Value , // -------------------------------------------------- etc. Its the Initialisation of mask to -2147483648 that causes the problem.

        P Offline
        P Offline
        prasad_som
        wrote on last edited by
        #4

        why you are assigning value to an int,which falls out of its range?

        T 1 Reply Last reply
        0
        • P prasad_som

          why you are assigning value to an int,which falls out of its range?

          T Offline
          T Offline
          toxcct
          wrote on last edited by
          #5

          it is not out of range, it is exactly the lower bound of a 32-bits signed int :

          2^32 = 4294967296
          (2^32)/2 = 2147483648

          so, signed int contains values into [-2147483648 ; +2147483647]


          TOXCCT >>> GEII power
          [toxcct][VisualCalc]

          P 1 Reply Last reply
          0
          • T toxcct

            it is not out of range, it is exactly the lower bound of a 32-bits signed int :

            2^32 = 4294967296
            (2^32)/2 = 2147483648

            so, signed int contains values into [-2147483648 ; +2147483647]


            TOXCCT >>> GEII power
            [toxcct][VisualCalc]

            P Offline
            P Offline
            prasad_som
            wrote on last edited by
            #6

            oops ! my mistake.:doh: just careless reading.

            1 Reply Last reply
            0
            • S sweep123

              Sorry its just a compiler Warning, but was trying to get rid of it. I have a structure:- typedef struct { char scaling [SCALE_LENGTH]; char format [FORMAT_LEN]; char dataRaw [DATA_LEN]; char dataEng [DATA_LEN]; char display1 [DISPLAY_LEN]; int base; int offset; **int mask;** int wordSize; int shift; int noFieldsBefore; int noFieldsAfter; double maximum; double minimum; double fullScale; }SIGNAL_DETAILS; And init:- // Initialise Data Structure for the Signals SIGNAL_DETAILS signal_details[NO_FIELDS] = { "1", // Scaling "Integer", // Display Format "0", // Raw Data String "0", // Engineering Data String "%04X", // Raw Display Format 382, // Signal Memory Base 0, // Signal Memory Offset **-2147483648, // Signal Mask** 32, // Word Size 0, // Signal Shift 0, // Signal position in word - Before 3, // Signal position in word - After 255.000000 , // Signal Max Value 0.000000 , // Signal Min Value 255.000000 , // Signal Full Scale Value , // -------------------------------------------------- etc. Its the Initialisation of mask to -2147483648 that causes the problem.

              R Offline
              R Offline
              Rage
              wrote on last edited by
              #7

              How about :

              {
              char scaling [SCALE_LENGTH];
              char format [FORMAT_LEN];
              char dataRaw [DATA_LEN];
              char dataEng [DATA_LEN];
              char display1 [DISPLAY_LEN];
              int base;
              int offset;
              signed int mask;
              int wordSize;
              int shift;
              int noFieldsBefore;
              int noFieldsAfter;
              double maximum;
              double minimum;
              double fullScale;
              }SIGNAL_DETAILS;

              ~RaGE();

              S 1 Reply Last reply
              0
              • R Rage

                How about :

                {
                char scaling [SCALE_LENGTH];
                char format [FORMAT_LEN];
                char dataRaw [DATA_LEN];
                char dataEng [DATA_LEN];
                char display1 [DISPLAY_LEN];
                int base;
                int offset;
                signed int mask;
                int wordSize;
                int shift;
                int noFieldsBefore;
                int noFieldsAfter;
                double maximum;
                double minimum;
                double fullScale;
                }SIGNAL_DETAILS;

                ~RaGE();

                S Offline
                S Offline
                sweep123
                wrote on last edited by
                #8

                Still the same compiler warning.

                T 1 Reply Last reply
                0
                • S sweep123

                  I get the following compile warning:- c:\TestProg\SigData.h(3625): warning C4146: unary minus operator applied to unsigned type, result still unsigned. I am assigning the value -2147483648 to an int field in a structure. Thanks.

                  T Offline
                  T Offline
                  Tim Smith
                  wrote on last edited by
                  #9

                  The documentation for C4146 talks about this problem. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore/html/C4146.asp[^] Tim Smith I'm going to patent thought. I have yet to see any prior art.

                  1 Reply Last reply
                  0
                  • S sweep123

                    Sorry its just a compiler Warning, but was trying to get rid of it. I have a structure:- typedef struct { char scaling [SCALE_LENGTH]; char format [FORMAT_LEN]; char dataRaw [DATA_LEN]; char dataEng [DATA_LEN]; char display1 [DISPLAY_LEN]; int base; int offset; **int mask;** int wordSize; int shift; int noFieldsBefore; int noFieldsAfter; double maximum; double minimum; double fullScale; }SIGNAL_DETAILS; And init:- // Initialise Data Structure for the Signals SIGNAL_DETAILS signal_details[NO_FIELDS] = { "1", // Scaling "Integer", // Display Format "0", // Raw Data String "0", // Engineering Data String "%04X", // Raw Display Format 382, // Signal Memory Base 0, // Signal Memory Offset **-2147483648, // Signal Mask** 32, // Word Size 0, // Signal Shift 0, // Signal position in word - Before 3, // Signal position in word - After 255.000000 , // Signal Max Value 0.000000 , // Signal Min Value 255.000000 , // Signal Full Scale Value , // -------------------------------------------------- etc. Its the Initialisation of mask to -2147483648 that causes the problem.

                    R Offline
                    R Offline
                    Roger Stoltz
                    wrote on last edited by
                    #10

                    What compiler are you using? Are you building for Win32? 'int' is per definition signed and the range of the type is –2,147,483,648 to 2,147,483,647 in a 32-bit environment. What happens if you change the radix of the value to hex and assign 0x80000000? (Since this looks like a bit mask perhaps this is preferred anyway...) -- Roger


                    It's supposed to be hard, otherwise anybody could do it!

                    1 Reply Last reply
                    0
                    • S sweep123

                      Still the same compiler warning.

                      T Offline
                      T Offline
                      toxcct
                      wrote on last edited by
                      #11

                      ok, i've got it... just have a look at the MSDN[^] : Practically, this occurs when the programmer is trying to express the minimum integer value, which is -2147483648. This value cannot be written as -2147483648 because the expression is processed in two stages: 1. The number 2147483648 is evaluated. Because it is greater than the maximum integer value of 2147483647, the type of 2147483648 is not int, but unsigned int. 2. Unary minus is applied to the value, with an unsigned result, which also happens to be 2147483648. ah, that was so simple :doh: just use INT_MIN instead of hard coding the value and don't forget to #include<limits.h>...


                      TOXCCT >>> GEII power
                      [toxcct][VisualCalc]

                      S 1 Reply Last reply
                      0
                      • T toxcct

                        ok, i've got it... just have a look at the MSDN[^] : Practically, this occurs when the programmer is trying to express the minimum integer value, which is -2147483648. This value cannot be written as -2147483648 because the expression is processed in two stages: 1. The number 2147483648 is evaluated. Because it is greater than the maximum integer value of 2147483647, the type of 2147483648 is not int, but unsigned int. 2. Unary minus is applied to the value, with an unsigned result, which also happens to be 2147483648. ah, that was so simple :doh: just use INT_MIN instead of hard coding the value and don't forget to #include<limits.h>...


                        TOXCCT >>> GEII power
                        [toxcct][VisualCalc]

                        S Offline
                        S Offline
                        sweep123
                        wrote on last edited by
                        #12

                        I tried 0x8000000 and it worked OK. But thanks for your post.

                        1 Reply Last reply
                        0
                        • S sweep123

                          Sorry its just a compiler Warning, but was trying to get rid of it. I have a structure:- typedef struct { char scaling [SCALE_LENGTH]; char format [FORMAT_LEN]; char dataRaw [DATA_LEN]; char dataEng [DATA_LEN]; char display1 [DISPLAY_LEN]; int base; int offset; **int mask;** int wordSize; int shift; int noFieldsBefore; int noFieldsAfter; double maximum; double minimum; double fullScale; }SIGNAL_DETAILS; And init:- // Initialise Data Structure for the Signals SIGNAL_DETAILS signal_details[NO_FIELDS] = { "1", // Scaling "Integer", // Display Format "0", // Raw Data String "0", // Engineering Data String "%04X", // Raw Display Format 382, // Signal Memory Base 0, // Signal Memory Offset **-2147483648, // Signal Mask** 32, // Word Size 0, // Signal Shift 0, // Signal position in word - Before 3, // Signal position in word - After 255.000000 , // Signal Max Value 0.000000 , // Signal Min Value 255.000000 , // Signal Full Scale Value , // -------------------------------------------------- etc. Its the Initialisation of mask to -2147483648 that causes the problem.

                          J Offline
                          J Offline
                          John R Shaw
                          wrote on last edited by
                          #13

                          typedef struct MyTag {...} MyStruct; MyStruct MyArray[MYSIZE] = { {...}, {...}, etc.. }; Notice the embeded "{...}", each of these represent a seperate struct item in the array. I suspect that because you are not doing this, each of the items that you enter (seperated by a ',') may be considered initialization of seprate item structures. I could be wrong about this, but I have seen this type of error many in my career, and the solution has always been the same. INTP Every thing is relative...

                          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