By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,433 Members | 1,827 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,433 IT Pros & Developers. It's quick & easy.

Any idea about this warning

P: n/a
Hi all,

While resolving the below sentence

#ifdef (CONFIG_COMMANDS & CFG_CMD_IDE)

The compiler is giving warning as

warning: the right operand of "&" changes sign when promoted

Is it related to stack.

Regards,
Sunil.

Nov 15 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
Here CONFIG_COMMANDS is defined as
(CFG_CMD_ALL & ~CFG_CMD_NONSTD)

Nov 15 '05 #2

P: n/a
"Sunil" <su***********@gmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
While resolving the below sentence

#ifdef (CONFIG_COMMANDS & CFG_CMD_IDE)


I suspect you wanted #if rather than #ifdef.

- Bill
Nov 15 '05 #3

P: n/a
Sorry for the mistake,
It is #if

But the remaining question is correct.

Question:
-------------
While resolving the below sentence

#define CONFIG_COMMANDS (CFG_CMD_ALL & ~CFG_CMD_NONSTD)
#if (CONFIG_COMMANDS & CFG_CMD_IDE)
The compiler is giving warning for the second line

warning: the right operand of "&" changes sign when promoted

Is it related to stack.

Nov 15 '05 #4

P: n/a
"Sunil" <su***********@gmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
Sorry for the mistake,
It is #if

But the remaining question is correct.

Question:
-------------
While resolving the below sentence

#define CONFIG_COMMANDS (CFG_CMD_ALL & ~CFG_CMD_NONSTD)
#if (CONFIG_COMMANDS & CFG_CMD_IDE)
The compiler is giving warning for the second line

warning: the right operand of "&" changes sign when promoted
OK. What are CFG_CMD_ALL and CFG_CMD_NONSTD ?

Perhaps you needed ! (logical not) rather than ~ (mathematical complement)
before CFG_CMD_NONSTD ?
Is it related to stack.


Oh, that's a question. I misread that as "It is related to the stack." rather
than "Is it related to the stack?".

Probably not.

- Bill
Nov 15 '05 #5

P: n/a
Mac
On Thu, 27 Oct 2005 21:05:36 -0700, Sunil wrote:
Hi all,

While resolving the below sentence

#ifdef (CONFIG_COMMANDS & CFG_CMD_IDE)

The compiler is giving warning as

warning: the right operand of "&" changes sign when promoted

Is it related to stack.

Regards,
Sunil.


The warning seems perfectly clear.

What exactly do you want to know?

--Mac

Nov 15 '05 #6

P: n/a
Le 28-10-2005, Sunil <su***********@gmail.com> a écrit*:
Hi all,

While resolving the below sentence

#ifdef (CONFIG_COMMANDS & CFG_CMD_IDE)

The compiler is giving warning as

warning: the right operand of "&" changes sign when promoted


Without any other information, I assume that one operand
is a signed integer type, the other an unsigned one,
and the compiler warns you that one of both will be
promoted and change its sign.

Look in your code to know wich one is signed, which
one is not, and in a C book the promotion rules.

Marc Boyer
Nov 15 '05 #7

P: n/a
I see I could have explained that a bit better earlier this morning.

"William J. Leary Jr." <Bi********@msn.com> wrote in message
news:iJ********************@comcast.com...
"Sunil" <su***********@gmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
While resolving the below sentence

#define CONFIG_COMMANDS (CFG_CMD_ALL & ~CFG_CMD_NONSTD)
#if (CONFIG_COMMANDS & CFG_CMD_IDE)

The compiler is giving warning for the second line
warning: the right operand of "&" changes sign when promoted


OK. What are CFG_CMD_ALL and CFG_CMD_NONSTD ?

Perhaps you needed ! (logical not) rather than ~ (mathematical complement)
before CFG_CMD_NONSTD ?


After expansion, the second line becomes:

#if ((CFG_CMD_ALL & ~CFG_CMD_NONSTD) & CFG_CMD_IDE)

It's complaining about the first &, not the second.

Again, try ! instead.

But also, how is CFG_CMD_NONSTD defined? It may make a difference, especially
if it's

#define CFG_CMD_NONSTD

for true and just not defined at all if not. In this case, if it's not
defined, your statement expands to:

#if ((CFG_CMD_ALL & ~) & CFG_CMD_IDE)

which has going to be a problem.

- Bill

Nov 15 '05 #8

P: n/a

In article <Gb********************@comcast.com>, "William J. Leary Jr." <Bi********@msn.com> writes:
"William J. Leary Jr." <Bi********@msn.com> wrote in message
news:iJ********************@comcast.com...
"Sunil" <su***********@gmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
While resolving the below sentence

#define CONFIG_COMMANDS (CFG_CMD_ALL & ~CFG_CMD_NONSTD)
#if (CONFIG_COMMANDS & CFG_CMD_IDE)

The compiler is giving warning for the second line
warning: the right operand of "&" changes sign when promoted
OK. What are CFG_CMD_ALL and CFG_CMD_NONSTD ?


Presumably CFG_CMD_ALL represents a bit vector, and CFG_CMD_NONSTD
one or more of the bits. The OP should have provided this
information (and the value of CFG_CMD_IDE), though.
After expansion, the second line becomes:

#if ((CFG_CMD_ALL & ~CFG_CMD_NONSTD) & CFG_CMD_IDE)

It's complaining about the first &, not the second.

Again, try ! instead.
I strongly suspect that is wrong. The use of bitwise-and (&) rather
than logical-and (&&), and the general form of the expression,
strongly suggest that this expression is meant to test if a
particular bit (or set of bits) is set in the left operand.
But also, how is CFG_CMD_NONSTD defined?


This is indeed the pertinent question. I suspect it's something
like

#define CFG_CMD_NONSTD 2

or

#define CFG_CMD_NONSTD (1<<1)

or perhaps something like

#define CFG_CMD_A 0x01
#define CFG_CMD_B 0x02

/* vector of "nonstandard" commands */
#define CFG_CMD_NONSTD (CFG_CMD_A | CFG_CMD_B)

And the diagnostic that the OP is getting is probably due to using
the binary-negation operator (~) on a signed integer constant, which
will produce a result with the opposite sign. (In two's-complement,
for example, ~1 == -2.)

The simple fix would seem to be changing the definition of
CFG_CMD_NONSTD, or of the other macros that compose it if it's an
expression, to use unsigned integer constants, as in:

#define CFG_CMD_NONSTD 2u

--
Michael Wojcik mi************@microfocus.com

Q: What is the derivation and meaning of the name Erwin?
A: It is English from the Anglo-Saxon and means Tariff Act of 1909.
-- Columbus (Ohio) Citizen
Nov 15 '05 #9

P: n/a
"Michael Wojcik" <mw*****@newsguy.com> wrote in message
news:dj*********@news4.newsguy.com...
After expansion, the second line becomes:

#if ((CFG_CMD_ALL & ~CFG_CMD_NONSTD) & CFG_CMD_IDE)

It's complaining about the first &, not the second.

Again, try ! instead.


I strongly suspect that is wrong.


You're right. I should have tried compiling it here.
But also, how is CFG_CMD_NONSTD defined?


This is indeed the pertinent question. I suspect it's something
like

#define CFG_CMD_NONSTD 2


Actually, that works (here).

I've used this as test code:

#define CFG_CMD_ALL 1
#define CFG_CMD_NONSTD 2
#define CFG_CMD_IDE 1
#define CONFIG_COMMANDS (CFG_CMD_ALL & ~CFG_CMD_NONSTD)
#if CFG_CMD_ALL
#if CONFIG_COMMANDS
#if (CONFIG_COMMANDS & CFG_CMD_IDE)

This all compiles, until it complains that I didn't close the #ifs.

When I change any of those to remove the value, as in
#define CFG_CMD_ALL
I get
x.c(5) : fatal error C1017: invalid integer constant expression

So, what they're defined as is entirely relevant.

Oddly, this code looks familiar to me. I recall working an open source program
which ran on DOS, Unix, WIndows and Linux. It had something like this:

#ifdef PLATFORM_Z
#define CFG_CMD_ALL
/* #define CFG_CMD_NONSTD - Platform Z is standard*/
#define CFG_CMD_IDE
#endif

#ifdef PLATFORM_Y
#define CFG_CMD_ALL
#define CFG_CMD_NONSTD
/* #define CFG_CMD_IDE - Platform Y doesn't support the IDE */
#endif

then used #ifdefs and #ifndefs with them.

#ifdef CFG_CMD_ALL
#ifndef CFG_CMD_NONSTD
#define CONFIG_COMMANDS
#else
#undefine CONFIG_COMMANDS
#endif
... and so on...

- Bill
Nov 15 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.