Compiler Warnings

N

News

I'm new to c and gcc. I was wondering if anyone can point me to a web page
or book that has a list of the warning messages and their meanings.

Are the warnings the same no matter what compiler you use, or are they
different for each compiler? I have looked all over the gcc web site, but I
can't find anything that explains what the warnings are.

If someone could take the time to help me out and direct me to some info
about this, I'd appriciate it.

Thanks
 
B

Ben Pfaff

News said:
I'm new to c and gcc. I was wondering if anyone can point me to a web page
or book that has a list of the warning messages and their meanings.

Unlike some compilers' warnings, GCC's are meant to be
self-explanatory. There isn't a place, that I know of, which has
the explanations you are looking for.

If there is a specific warning, or a few, that you would like
explained, c.l.c is a good place to ask. Note that c.l.c is
generally not the right place to ask questions about specific
compilers, but warnings tend to be more about C than about
compilers.
Are the warnings the same no matter what compiler you use, or are they
different for each compiler? I have looked all over the gcc web site, but I
can't find anything that explains what the warnings are.

Every compiler has different warnings.
 
K

Kevin Goodsell

Ben said:
Every compiler has different warnings.

This is true in two different senses: first, the actual text that is
emitted for a given condition may be different. Second, the choice
whether or not to emit a warning for some condition may be different.

In other words, code that causes one compiler to generate a warning may
cause a different compiler to generate a different warning or no warning
at all.

The standard requires certain conditions to generate a diagnostic, so
some conditions must evoke some form of warning from a
standard-compliant compiler.

-Kevin
 
G

glen herrmannsfeldt

Unlike some compilers' warnings, GCC's are meant to be
self-explanatory. There isn't a place, that I know of, which has
the explanations you are looking for.

IBM, at least for the mainframes, and even for other systems, has a
tradition of supplying manuals describing all the messages a given
program could generate. Usually it will describe in more detail than
the printed message the cause, and suggested action to take.

There may be other companies that have a similar system, but it is
not so common. Though I believe that early microsoft compilers
may have done it.

-- glen
 
R

Richard Heathfield

glen herrmannsfeldt wrote:

IBM, at least for the mainframes, and even for other systems, has a
tradition of supplying manuals describing all the messages a given
program could generate. Usually it will describe in more detail than
the printed message the cause, and suggested action to take.

I have fond (but admittedly vague) memories of these messages:

I40008291 An error has occurred.

Suggested action: Correct the error and re-submit the job.

;-)
 
J

Jakle

Thank you guys for the info. I remember when I was a kid my father would
have a pocket size book full of warnings he could look at if anything came
up. Like they say, I just have to keep coding and making mistakes, then I
will get less warnings, and also get familiar with what they are. Thanks
again
 
R

Richard Heathfield

Jakle said:
Thank you guys for the info. I remember when I was a kid my father would
have a pocket size book full of warnings he could look at if anything came
up. Like they say, I just have to keep coding and making mistakes, then I
will get less warnings, and also get familiar with what they are. Thanks
again


Why not train yourself, by making deliberate mistakes and watching what the
compiler does? For example, try leaving a semicolon off a declaration. Or
try using an undefined variable. Or try missing out a necessary header.
 
G

glen herrmannsfeldt

Richard Heathfield wrote:

(snip)
Why not train yourself, by making deliberate mistakes and watching what the
compiler does? For example, try leaving a semicolon off a declaration. Or
try using an undefined variable. Or try missing out a necessary header.

I remember a compiler I used to use (not a C compiler) that would
attempt to correct errors. (In the internal representation of the
source program only.) So it had messages like:

Semicolon missing, one inserted in line 123.

In the days of batch programming, it was useful to get as much
out of a compiler run as possible. This would allow the
compiler to get farther through the program, and find more
errors, before giving up.

I don't remember if it could detect unclosed comments, an easy
mistake to make in languages with multiline comments.

-- glen
 
G

glen herrmannsfeldt

Richard said:
glen herrmannsfeldt wrote:




I have fond (but admittedly vague) memories of these messages:

I40008291 An error has occurred.

Suggested action: Correct the error and re-submit the job.

Yes, some were like that. It does remind me, though, of the time
my program died with a Machine Check error on a system that charged
real money for CPU time, lines printed, etc. It took some
convincing to get credit for a problem that was not my fault.

Machine Check is a hardware error in the processor, that the
processor can detect. Memory parity might be one, though they
usually checked more than that.

-- glen
 
M

Mike Wahler

News said:
I'm new to c and gcc. I was wondering if anyone can point me to a web page
or book that has a list of the warning messages and their meanings.

The content and meanings of compiler warning (and error) messages
are unique to each compiler.
Are the warnings the same no matter what compiler you use,

No.

or are they
different for each compiler?
Yes.

I have looked all over the gcc web site, but I
can't find anything that explains what the warnings are.

I suggest you read more closely :). I'm sure the gcc manual
has these descriptions.

Also, if you have some code that's producing a warning you don't
understand, you can post it here and others will probably be able
to spot the trouble. But only post enough code to demonstrate the
problem.
If someone could take the time to help me out and direct me to some info
about this, I'd appriciate it.

Any questions about gcc, I'd direct to the gnu web site and/or newsgroups.

-Mike
 
C

Christopher Benson-Manica

Jakle said:
Thank you guys for the info. I remember when I was a kid my father would
(etc)

In the future, please include the relevant text of the person you are
replying to and make your own comments below it. It's considered
good manners here.
 
C

Christopher Benson-Manica

Richard Heathfield said:
I40008291 An error has occurred.
Suggested action: Correct the error and re-submit the job.

About as helpful as "No ROM BASIC, system halted"...
 
C

Christopher Benson-Manica

Kevin Goodsell said:
The standard requires certain conditions to generate a diagnostic, so
some conditions must evoke some form of warning from a
standard-compliant compiler.

When the appropriate compiler options are enabled, of course, i.e.
-ansi for gcc.
 
D

Dan Pop

In said:
Richard Heathfield wrote:

(snip)


I remember a compiler I used to use (not a C compiler) that would
attempt to correct errors. (In the internal representation of the
source program only.) So it had messages like:

Semicolon missing, one inserted in line 123.

VAX C used to do that. The warning codename was SEMICOLONADDED.

Dan
 
D

Dan Pop

In said:
The standard requires certain conditions to generate a diagnostic, so
some conditions must evoke some form of warning from a
standard-compliant compiler.

Nope, they must evoke some form of diagnostic. It's up to the implementor
to decide whether each specific condition is handled as a warning or as
an error.

IMO, users would be better served by compilers that handled each and
every required diagnostic as an error, reserving warnings for dubious
program constructs that don't require a diagnostic.

Dan
 
D

Dave Vandervies

When the appropriate compiler options are enabled, of course, i.e.
-ansi for gcc.

Without the appropriate options, it's not a standard-compliant compiler.

F'rexample, "gcc" without any options specified is a Rather Different
compiler than "gcc -W -Wall -ansi -pedantic -O".


dave

--
Dave Vandervies (e-mail address removed)
your a morron.
Beautiful. Classic sig block material.
--Richard Heathfield roasts a troll in comp.lang.c
 
K

Keith Thompson

glen herrmannsfeldt said:
I remember a compiler I used to use (not a C compiler) that would
attempt to correct errors. (In the internal representation of the
source program only.) So it had messages like:

Semicolon missing, one inserted in line 123.

The (non-C) compiler I used to work on did something similar. It
internally corrected any syntax errors until it managed to build a
syntactically correct representation of the input program. (This was
done only for error recovery; syntax errors, even correctable ones,
were considered fatal.)

If you fed it garbage (e.g., a file of English text), it would usually
reduce it to nothing, recognizing any keywords along the way.
 
D

Dan Pop

In said:
When the appropriate compiler options are enabled, of course, i.e.
-ansi for gcc.

It's actually -pedantic that enables most of the required diagnostics that
gcc doesn't generate by default. gcc -ansi is a conforming translator,
except for the diagnostics issue. For "full" conformance, you need
-ansi -pedantic. I used the double quotes because even with these
options there are floating point issues left, some of which can be cured
by -ffloat-store (at the expense of slowing down the generated code).

Dan
 
K

Kevin Bracey

IMO, users would be better served by compilers that handled each and
every required diagnostic as an error, reserving warnings for dubious
program constructs that don't require a diagnostic.

I agree with Dan totally on this point (for once), and that's what the
compiler I maintain tries to ensure. Every required diagnostic is an error or
serious error. Warnings are only advisory. Undefined behaviour may lead to
either or neither.

This means that the "implicit int" diagnostic is an error in C99 mode too. It
used to be a warning.

I don't know how I'd have coped learning C if I hadn't originally learnt on
such a compiler.
 
K

Kevin Bracey

In message <[email protected]>
Keith Thompson said:
The (non-C) compiler I used to work on did something similar. It
internally corrected any syntax errors until it managed to build a
syntactically correct representation of the input program.

The C compiler I maintain does pretty much exactly this, and will correct
most simple errors. It does bail out and skip until a terminator in the
event of a serious parse failure though.

For example, feeding it your last paragraph gives:

"c.x", line 1: Error: expected ')' or ',' - inserted ')' before '-'
"c.x", line 1: Error: function prototype formal 'non' needs type or class - 'int' assumed
"c.x", line 1: Error: declaration lacks type (assuming 'int'): 'The'
"c.x", line 1: Error: expected ';' or ',' - inserted ';' before '-'
"c.x", line 1: Serious error: Expecting <declarator> or <type> but found '-'
"c.x", line 4: Error: expected ';' or ',' - inserted ';' before <eof>

So it corrected it to

The (non);-C) ... program.;

And then interpreted it as

int The(int non);
 

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,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top