Compiler warnings vs remarks mystery

G

gil

Hi,

I'm trying to find the best way to work with compiler warnings. I'd
like to remove *all* warnings from the code, and playing around with
the warning level, I've noticed that compiling with /W3 I get warnings
that with /W4 are shown as remarks, e.g.:

warning #177: variable "Foo" was declared but never referenced

....is displayed as a "remark #177" with /W4. That doesn't fit the
definitions in Intel's help page. My questions are:

1. Why did the warning turn into a remark, is this a bug? If not, what
is the intention behind this behaviour? This doesn't include ALL
warnings, e.g.

warning #504: initial value of reference to non-const must be an
lvalue

remains a warning with /W4.

2. How come issues of conversion from "double" to "float" are
displayed only as remarks with w4? Usually they are w3 with other
compilers...?

3. Can remarks be eliminated altogether, and what is the best way (in
your opinion) to go with remarks/warnings?

Thanks,
Gil Moses.
 
V

Victor Bazarov

I'm trying to find the best way to work with compiler warnings. I'd
like to remove *all* warnings from the code, and playing around with
the warning level, I've noticed that compiling with /W3 I get warnings
that with /W4 are shown as remarks, e.g.:

warning #177: variable "Foo" was declared but never referenced

...is displayed as a "remark #177" with /W4. That doesn't fit the
definitions in Intel's help page. My questions are:

1. Why did the warning turn into a remark, is this a bug? If not, what
is the intention behind this behaviour? This doesn't include ALL
warnings, e.g.

warning #504: initial value of reference to non-const must be an
lvalue

remains a warning with /W4.

2. How come issues of conversion from "double" to "float" are
displayed only as remarks with w4? Usually they are w3 with other
compilers...?

3. Can remarks be eliminated altogether, and what is the best way (in
your opinion) to go with remarks/warnings?

Your questions concern the behaviour of a particular compiler. Those
aspects are not set forth by the language Standard, they are at the
discretion of any compiler manufacturer/vendor. Please contact Intel
technical support and ask *them* about those things.

IMO the best way to eliminate the warnings is to write perfect code.
Since perfection is [usually] unattainable, it is allowed to disable
warnings if there is no way to get rid of them, or just ignore them
if there is a desire to see that your code is not perfect (from the
compiler creators' point of view).

V
 
M

Marcus Kwok

I'm trying to find the best way to work with compiler warnings. I'd
like to remove *all* warnings from the code, and playing around with
the warning level, I've noticed that compiling with /W3 I get warnings
that with /W4 are shown as remarks

The Standard doesn't define such things as "remarks" or "warnings". All
the Standard requires is that the compiler issue "diagnostics" for
certain problems with your code. However, it doesn't define what form
the diagnostic should take. For all the Standard requires, the
diagnostic can just say, "Problem!" without specifying what it is;
however, that would be a Quality of Implementation (QoI) issue and few
people would be likely to use that compiler.

What I'm trying to say is that you need to ask the support group for
your specific compiler.
 
J

James Kanze

I'm trying to find the best way to work with compiler warnings. I'd
like to remove *all* warnings from the code,

That's generally a good goal, but all of the compilers I've used
have one or two idiotic warnings, which can't reasonably be
avoided. (More than one compiler I've used has output warnings
from its own header files:).) At the very least, be sure you
understand why the warning is there.

In a larger project, it's generally a good idea to start with
the rule that all code must be compiled at the maximum warning
level, and that no warnings are permitted. Then, as programmers
run into warnings that aren't practical to avoid, you introduce
exceptions, either on a one time basis (the code does something
special which requires a normally dangerous construct), or
generally (the compiler is getting in a tissy about nothing).
and playing around with the warning level, I've noticed that
compiling with /W3 I get warnings that with /W4 are shown as
remarks, e.g.:

The compilers I use don't distinguish.
warning #177: variable "Foo" was declared but never referenced
...is displayed as a "remark #177" with /W4. That doesn't fit the
definitions in Intel's help page. My questions are:
1. Why did the warning turn into a remark, is this a bug?

For any specific warning, you'll have to ask the compiler
vendor.
If not, what is the intention behind this behaviour? This
doesn't include ALL warnings, e.g.
warning #504: initial value of reference to non-const must be an
lvalue
remains a warning with /W4.

That *isn't* a warning, or at least shouldn't be. That is an
error, and conformant compilers won't compile such code.
2. How come issues of conversion from "double" to "float" are
displayed only as remarks with w4? Usually they are w3 with other
compilers...?

The compilers I've seen don't usually say anything about
narrowing conversions. There are historical reasons which mean
that most such warnings are irrelevant, and rather than flood
the output with irrelevant warnings, they don't worry about it.
In many ways, it's a shame, but we can't change history.
3. Can remarks be eliminated altogether, and what is the best
way (in your opinion) to go with remarks/warnings?

Again, most compilers don't distinguish. In the end: ideally,
you should strive for no output from the compiler, but
practically, you're going to have to evaluate, and allow some.
The decision should be based on your requirements, not any
categorization by the compiler, however.
 
P

Pete Becker

James said:
That *isn't* a warning, or at least shouldn't be. That is an
error, and conformant compilers won't compile such code.

Conformant compilers will issue a diagnostic. That's all that's required
by the standard. And the meaning of "diagnostic" is up to the
implementor. Every compiler I know of documents warnings as a form of
diagnostic.

--

-- Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com)
Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." (www.petebecker.com/tr1book)
 
J

James Kanze

James Kanze wrote:
Conformant compilers will issue a diagnostic. That's all that's required
by the standard. And the meaning of "diagnostic" is up to the
implementor. Every compiler I know of documents warnings as a form of
diagnostic.

That's true. Most compilers "document" what is a diagnostic in
the sense of the standard as "anything the compiler happens to
output". (They don't use exactly those words, but that's the
real meaning.)
 
G

Gennaro Prota

Pete said:
Conformant compilers will issue a diagnostic. That's all that's required
by the standard. And the meaning of "diagnostic" is up to the
implementor. Every compiler I know of documents warnings as a form of
diagnostic.

That's a bit inexact. A diagnostic is always an output message. What
is up to the implementation is choosing and documenting which of its
output messages are diagnostics.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top