473,320 Members | 1,990 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Any idea about this warning

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
9 1603
Here CONFIG_COMMANDS is defined as
(CFG_CMD_ALL & ~CFG_CMD_NONSTD)

Nov 15 '05 #2
"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
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
"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
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
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
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

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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: mikron30 | last post by:
In the following code I am getting the following warning warning C4213: nonstandard extension used : cast on l-value class X { public: operator bool() {}; }; class Y
1
by: Raed Sawalha | last post by:
when i build asp.net application i have theses warnings messages ,what they mean? Preparing resources... Updating references... Warning: The dependency 'EW_Calender, Version=2.5.2055.20123,...
0
by: Manish | last post by:
PHP INI File Setting ------------------------------------------------------------------------------------------------------------------ error_reporting = E_ALL & ~E_NOTICE No warning message are...
83
by: deppy_3 | last post by:
Hi.I am started learning Programm language C before some time.I am trying to make a programm about a very simple "sell shop".This programm hasn't got any compile problem but when i run it i face...
28
by: onkar | last post by:
This idea might be vey crazy. But I hope to get answers to this .. from comp.lang.c If a compiler is designed such that it automatically adds a free() matching every malloc() then is it not a...
1
by: speralta | last post by:
For some reason the text in h2 tag is displaying as white in IE. http://www.salperalta.com/ <td class="sidebar" id="sidebar-right"> <div class="block block-listing" id="block-listing-0">...
5
by: holmescn | last post by:
what is the meaning of warning attributes ignored on template instantiation. i got it when i compiled stlport 5.1.3. anybody can help me ? thx!
9
by: dewi | last post by:
Dear All, I have several problem about VC++. I succeed to convert Simulink MATLAB to C code using Real-Time Workshop. I am trying to compile a C code using Visual C++ and found the error. Can...
24
by: lector | last post by:
#include <stdio.h> #include <math.h> #define M_PI 3.14159 int main(void) { double theta, phi, sinth; double count; double incr; double s;
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.