|
But the issue is, as I keep repeating, that this is not the correct way to use enum s. If you want to combine flag values then use #define , if you want to select one value from a set then use enum . That is the rule for C and C++, and that is why the compiler complains about your code.
|
|
|
|
|
Thank you Richard for your patience. BTW, is a legacy code, is not written by me. There will be more suitable to chnage this enum to a struct and where to overload |= operator ?
modified 6-Oct-19 12:57pm.
|
|
|
|
|
Why would you change it to a struct, it only requires a single integer variable to hold all the flags.
int flags = FILE_READONLY | FILE_HIDDEN;
flags |= FILE_SYSTEM;
|
|
|
|
|
So the finest solution is to take these values from enum and put them as #define s. I will do this change.
|
|
|
|
|
I am afraid that I cannot change that enum into #defines, because I have:
na->flags |= flag;
where
FILE_FLAGS flag;
and
na is struct level1, and inside this level1 struct, I have
struct level1
{
FILE_FLAGS flags;
....
};
I have entered in some deadlock ? Please help me to solve this error ...
|
|
|
|
|
Try to declare both flags and flag as int
|
|
|
|
|
Yes, but FILE_FLAGS is enum with int values ...
|
|
|
|
|
Then, as Richard already suggested replace this enum with a set of #define.
|
|
|
|
|
Agree, but that enum is a part of another struct ... so, how can I put as part of a struct several #defines ?
|
|
|
|
|
Of course you can change it to #defines. The definition of FILE_FLAGS then becomes an int type. And then the rest of the code should compile correctly.
|
|
|
|
|
I am not get something, so forgive me.
I have moved those enum values as #defines , but of course, now I get error from struct : doesn't know who is FILE_FLAGS flags; from level1 struct.
#define FILE_READONLY = 0x00000001
#define FILE_HIDDEN = 0x00000002
#define FILE_SYSTEM = 0x00000004
of course, FILE_FLAGS enum has disappeared ... obviously, I don't understood something ... but what ?
struct level1
{
FILE_FLAGS flags; ....
};
|
|
|
|
|
_Flaviu wrote: struct level1
{
FILE_FLAGS flags;
....
};
Try
struct level1
{
int flags; ....
};
|
|
|
|
|
Ok, but even flag is comming as function parameter, just like this:
static void SomeFunction(level1* na, FILE_FLAGS flag)
{
....
na->flags |= ~flag;
....
}
So, I guess I cannot give up FILE_FLAGS enum ... don't I ?
|
|
|
|
|
Change this parameter to be
static void SomeFunction(level1* na, int flag)
{
|
|
|
|
|
Add this line somewhere before the first reference to FILE_FLAGS :
typedef int FILE_FLAGS;
|
|
|
|
|
I encounter another error if I made these modifications:
data->com = na->flags & ATTR_IS_COMPRESSED;
(where data->com is int )
because now ATTR_IS_COMPRESSED is #define , not part of enum FILE_FLAGS ...
modified 8-Oct-19 5:37am.
|
|
|
|
|
What is data->com ?
_Flaviu wrote: because now ATTR_IS_COMPRESSED is #define , not part of enum FILE_FLAGS That is not the reason. I can only assume that you have done a partial change and some parts of your code are still incorrect. If you still have the FILE_FLAGS enum then it is going to cause problems.
It would probably help if you showed all the code portions that are connected. It is difficult to be certain of the answers when looking at only a single line of code.
|
|
|
|
|
I still cannot see enough information. Please provide what I previously requested and reply to this message. Please do not email me personally.
|
|
|
|
|
I only said that I updated the previous post. Ok, I will come with new informations.
|
|
|
|
|
The fact is like that: I have an error:
error C2059: syntax error : '='
the error is reported here:
data->com = na->flags & ATTR_IS_COMPRESSED;
where:
data is a struct:
struct data
{
.....
int com;
...
};
and na is
RECORD* na;
and RECORD is:
typedef struct {
....
....
int flags;
.....
}RECORD;
and
ATTR_IS_COMPRESSED is from here (from my modifications):
typedef int ATTR_FLAGS;
#define ATTR_IS_COMPRESSED = 0x0001
#define ATTR_COMPRESSION_MASK = 0x00ff
|
|
|
|
|
Not sure why you posted all that back to front ...
However there are a couple of simple mistakes:
#define statements do not require an = sign. They should be
#define ATTR_IS_COMPRESSED 0x0001
#define ATTR_COMPRESSION_MASK 0x00ff
The name data refers to a struct definition, not a variable. You need something like:
typedef struct
{
.....
int com;
...
} DATA;
DATA* data;
I am assuming that you actually assign the memory required for both structures at some point further on.
|
|
|
|
|
That was the problem, on #define : I assigned with '='. My bad !
|
|
|
|
|
This warning from post title is more an information than a warning: unary minus operator applied to unsigned type, result still unsigned
but is signaled here:
static unsigned char buffer[512];
static long long var = -sizeof(buffer) - 1;
Still, how can I rid of this warning ?
|
|
|
|
|
You can cast the result of the sizeof call to a long long prior to apply it the unary minus operator:
static long long var = -((long long)sizeof(buffer)) - 1;
It makes sense when you think of what should the result be when you try to negate a value of a type which does not accept negative values.
"Five fruits and vegetables a day? What a joke!
Personally, after the third watermelon, I'm full."
|
|
|
|
|
Thanks. That warning has disappeared.
modified 4-Oct-19 10:19am.
|
|
|
|