Can Someone Explain Error Message
-
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.
-
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. -
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.why you are assigning value to an int,which falls out of its range?
-
why you are assigning value to an int,which falls out of its range?
-
it is not out of range, it is exactly the lower bound of a 32-bits signed int :
2^32 = 4294967296
(2^32)/2 = 2147483648so, signed int contains values into [-2147483648 ; +2147483647]
TOXCCT >>> GEII power
[toxcct][VisualCalc]oops ! my mistake.:doh: just careless reading.
-
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.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();
-
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();
-
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.
-
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.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!
-
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] -
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] -
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.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...