signed value is out of range for enum constant
-
I am trying to convert some code from Linux to Windows. So, I've met two warnings at one single line of code:
typedef enum {
SOME_LINK =
const le64(0x022B4AAC34546A39ULL), // <-- warning C4341: 'SOME_LINK' : signed value is out of range for enum constant
// <-- warning C4309: 'initializing' : truncation of constant value
....of course, I can disable this warning, but I want to do things right :) how can I get rid of this warning by a correction ? It is possible ?
-
I am trying to convert some code from Linux to Windows. So, I've met two warnings at one single line of code:
typedef enum {
SOME_LINK =
const le64(0x022B4AAC34546A39ULL), // <-- warning C4341: 'SOME_LINK' : signed value is out of range for enum constant
// <-- warning C4309: 'initializing' : truncation of constant value
....of course, I can disable this warning, but I want to do things right :) how can I get rid of this warning by a correction ? It is possible ?
-
Default enum is an int. You need a long.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food
-
I am trying to convert some code from Linux to Windows. So, I've met two warnings at one single line of code:
typedef enum {
SOME_LINK =
const le64(0x022B4AAC34546A39ULL), // <-- warning C4341: 'SOME_LINK' : signed value is out of range for enum constant
// <-- warning C4309: 'initializing' : truncation of constant value
....of course, I can disable this warning, but I want to do things right :) how can I get rid of this warning by a correction ? It is possible ?
A standard 'enum' in C can only be of types 'int' or 'unsigned int'. This value is an 'unsigned long long'. This sort of thing is usually done in order to aggregate constants into a namespace. Unfortunately, Standard C does not allow this. If your 'enum' is, for example, called LINKS, try:
typedef unsigned long long LINKS;
\#define SOME_LINK …Freedom is the freedom to say that two plus two make four. If that is granted, all else follows. -- 6079 Smith W.
-
I am trying to convert some code from Linux to Windows. So, I've met two warnings at one single line of code:
typedef enum {
SOME_LINK =
const le64(0x022B4AAC34546A39ULL), // <-- warning C4341: 'SOME_LINK' : signed value is out of range for enum constant
// <-- warning C4309: 'initializing' : truncation of constant value
....of course, I can disable this warning, but I want to do things right :) how can I get rid of this warning by a correction ? It is possible ?
-
Quote:
of course, I can disable this warning, but I want to do things right
Do NOT disable the warning. Data would be truncated, (that is an error).
-
Totally agree with you, that is why I asked here a solution. I have declared like this that enum:
typedef enum LINK : unsigned long long {
SOME_LINK = 0x01F5E4CA2A46E33ULL,
...and those warning has gone ... I hope is ok now.