error and warning

A

asit

Are warnings equally dangerous like errors ????

What is the difference between errors and warnings ??
 
J

Joachim Schmitz

asit said:
Are warnings equally dangerous like errors ????
Sometimes yes, sometimes even more dangerrous, sometimes less. Make sure you
understand what the warning tries to tell you
What is the difference between errors and warnings ??
Usualla errors prevent the compiler to finish it's work, while with warning
that (usually) doesn't happen

Bye, Jojo
 
D

dj3vande

Are warnings equally dangerous like errors ????

It depends on the warning.
Some of them are harmless. Many of them are more dangerous, since
careless programmers assume they're irrelevant, where errors obviously
need to be fixed.

What is the difference between errors and warnings ??

If a compiler issues a warning, it probably thinks it can come up with
a sensible way to interpret what you gave it, or suspects that a
well-defined and unambiguous construct is nevertheless probably not
what you intended to say.
An error usually means the compiler is sufficiently confused (or the
code is sufficiently broken) to not be able to continue.

(Note that this is an implementation detail; the C language only
requires "diagnostics", and doesn't distinguish between errors and
warnings.)


dave
 
L

Lew Pitcher

Are warnings equally dangerous like errors ????

What is the difference between errors and warnings ??

Errors tell you that what you've written is wrong and cant be done

Warnings tell you that what you've written is ambigious, and might not
do what you expect it to do.
 
J

jameskuyper

(e-mail address removed) wrote:
....
(Note that this is an implementation detail; the C language only
requires "diagnostics", and doesn't distinguish between errors and
warnings.)

However, I've found that it's commonplace for mandatory diagnostics to
be reported as errors, while other diagnostics tend to be labeled as
warnings.
 
R

Richard Heathfield

asit said:
Are warnings equally dangerous like errors ????

What is the difference between errors and warnings ??

An error message indicates a mistake in your code. A warning almost always
indicates a mistake in your code. The C language doesn't distinguish
between them - it only requires that, in certain circumstances, a
"diagnostic message" is produced.

Over time, you will become familiar with diagnostic messages (what many
implementations call "errors" and "warnings") and their causes, and you
will learn how to deal with them. They can seem very baffling to the
beginner, but they generally do make some kind of sense, although they are
not always good at suggesting a fix. For example, for a message like
"integer converted to pointer without a cast", the fix is probably *not*
to add a cast - it is more likely that you forgot to #include a header.

You will learn fastest if you:

(a) set your compiler's warning level to the highest possible;
(b) deal with the *first* warning (or error) *first*. Mistakes of typing
and punctuation frequently lead to a cascade of messages because the
compiler has been totally confused by the typo. If you find yourself
facing dozens of errors, fixing the first message first and then
re-compiling will very often remove a great many of them at one stroke.
 
J

Joachim Schmitz

Joachim said:
Sometimes yes, sometimes even more dangerrous, sometimes less. Make
sure you understand what the warning tries to tell you

Usualla errors prevent the compiler to finish it's work, while with
warning that (usually) doesn't happen
From your other article I gather that you a) use GCC abd b) are pretty new
to C
, so here's an extra hint:
uase gcc's option -Wall -Werror. While -Wall givesa a pretty complete set of
warnings (not all possible ones, but a reasonable subset) -Werror causes
them to be treated as errors (and hence the gcc refuses to compile the
code).
In this group you may also consider using -ansi -pedantic, to get extra
warnings for everything beond the C-Standard.
And as said earlier: only warning you fully understand may get ignored, so
better don't ignore any, but rewrite your code instead.

Bye, Jojo
 
K

Keith Thompson

(e-mail address removed) wrote:
...

However, I've found that it's commonplace for mandatory diagnostics to
be reported as errors, while other diagnostics tend to be labeled as
warnings.

But that's not universal. For example, gcc often issues mere warnings
for constraint violations, presuambly if the authors thought they
could construct a reasonable interpretation for the code.
 
U

user923005

Are warnings equally dangerous like errors ????

What is the difference between errors and warnings ??

Generally, the compiler refuses to emit code with an error and will
still emit code with a warning.

For that reason, warnings are usually more dangerous than errors,
because you can ignore warnings (perhaps unwisely) but you can't
ignore errors.

Finally, something that causes no diagnostic at all is likely to be
the most serious sort of problem. It could be a logic error or
undefined behavior or the programmer casting away an important
warning.
 
F

Flash Gordon

Joachim Schmitz wrote, On 14/01/08 15:18:
From your other article I gather that you a) use GCC abd b) are pretty new
to C
, so here's an extra hint:
uase gcc's option -Wall -Werror. While -Wall givesa a pretty complete set of
warnings (not all possible ones, but a reasonable subset) -Werror causes
them to be treated as errors (and hence the gcc refuses to compile the
code).
In this group you may also consider using -ansi -pedantic, to get extra
warnings for everything beond the C-Standard.

I think you meant using -ansi -pedantic to get all the diagnostics
*required* by the C standard. It is -Wall and -Wextra that give you
warnings beyond those required by the C standard.
And as said earlier: only warning you fully understand may get ignored, so
better don't ignore any, but rewrite your code instead.

Please note that you have to understand the warning *before* fixing your
code. For example adding a cast because that looks like what the warning
is suggesting is almost always the wrong thing to do.
 
J

Joachim Schmitz

Flash said:
Joachim Schmitz wrote, On 14/01/08 15:18:

I think you meant using -ansi -pedantic to get all the diagnostics
*required* by the C standard. It is -Wall and -Wextra that give you
warnings beyond those required by the C standard.
Well, I meant warning about things that are non-standard
Please note that you have to understand the warning *before* fixing
your code. For example adding a cast because that looks like what the
warning is suggesting is almost always the wrong thing to do.
Indeed

bye, Jojo
 
F

Flash Gordon

Joachim Schmitz wrote, On 15/01/08 08:49:
Well, I meant warning about things that are non-standard

<snip>

OK, I miss-understood what you intended to say. So now I'll address what
you intended...

Adding -ansi -pedantic will, in some senses, not warn about everything
that is non-standard. For example it still will not warn about all
instances of undefined behaviour (-ansi -pedantic -Wall -Wextra comples
closer, but still is not complete) since doing so would be equivalent to
the halting problem.
 

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
474,263
Messages
2,571,064
Members
48,769
Latest member
Clifft

Latest Threads

Top