When to emit diagnistics

J

jacob navia

Recently we had a discussion about the following code:

void f(long *lp) { *lp = 0; }
int main(void) { int i; f(&i); return i; }

lcc-win doesn't emit any diagnostic in normal mode, and doesn't
emit a diagnostic with the higher warning level.

It emits a diagnostic only in the highest warning level:

lcc -A -A foo.c

will diagnostic that with a warning.

Why?

Because under windows (32 and 64 bits) there is
absolutely no PRACTICAL difference between a
long and an int. They are completely equivalent types.

The diagnostic would just add CLUTTER and NOISE to
the output of the compiler.

The problem is that if the compiler emits too many diagnostics
the important ones will go unnoticed, swallowed by the noise
of the unimportant ones.

Note that Microsoft C, for instance will not diagnose this
even with the highest warning level.

This are the reasons behind the decision. Some people like
heathfield or becarisse use this as a "proof that lcc-win is
useless", etc. Their usual stuff. Note that lcc-win is not
just for pleasing pedants in comp.lang.c but it is useful
for doing REAL work. The objective is not to please
pedants here.
 
J

Joachim Schmitz

jacob said:
Recently we had a discussion about the following code:

void f(long *lp) { *lp = 0; }
int main(void) { int i; f(&i); return i; }

lcc-win doesn't emit any diagnostic in normal mode, and doesn't
emit a diagnostic with the higher warning level.

It emits a diagnostic only in the highest warning level:

lcc -A -A foo.c

will diagnostic that with a warning.
Good. One problem solved. Now document that switch in your manual.
Why?

Because under windows (32 and 64 bits) there is
absolutely no PRACTICAL difference between a
long and an int. They are completely equivalent types.

The diagnostic would just add CLUTTER and NOISE to
the output of the compiler.

The problem is that if the compiler emits too many diagnostics
the important ones will go unnoticed, swallowed by the noise
of the unimportant ones.
All valid points, indeed.
Note that Microsoft C, for instance will not diagnose this
even with the highest warning level.
Haven't tested this myself, but a far as I understood others (namely RH), it
it does diagnose this if called _in conforming mode_. So please don't
continue comparing apples with peaches.
This are the reasons behind the decision. Some people like
heathfield or becarisse use this as a "proof that lcc-win is
useless", etc. Their usual stuff. Note that lcc-win is not
just for pleasing pedants in comp.lang.c but it is useful
for doing REAL work. The objective is not to please
pedants here.
Nobody claimed win-lcc to be useless. The only claim here (and plenty proof
for it) was that win-lcc does not (unlike your claim) conform to either
C89/C90 or C99.
So it is a compiler for a C-like language, no more, no less. That doesn't
make it useless.

Bye, Jojo
 
S

santosh

jacob said:
Recently we had a discussion about the following code:

void f(long *lp) { *lp = 0; }
int main(void) { int i; f(&i); return i; }

lcc-win doesn't emit any diagnostic in normal mode, and doesn't
emit a diagnostic with the higher warning level.

It emits a diagnostic only in the highest warning level:

lcc -A -A foo.c

The problem is you have not (as far as I can tell) *documented* this
switch combination. Undocumented features are IMO worse than
unimplemented features.
will diagnostic that with a warning.

Why?

Because under windows (32 and 64 bits) there is
absolutely no PRACTICAL difference between a
long and an int. They are completely equivalent types.

You are assuming here that any Standard C program compiled with lcc-win
under Windows has no chance of later being ported to a different
system.

This warning is absolutely essential for a user who considers
portability to be important.
The diagnostic would just add CLUTTER and NOISE to
the output of the compiler.

Then why not add a specific switch for enabling warnings of this class,
like say gcc? Or you could arrange for the '-A' switch to take a
numeric value which would specify the warning level. Necessitating
*two* instances of the '-A' switch is very counter-intuitive.

Don't be afraid to add more command line switches. A C compiler is a
serious tool, and a professional programmer is expected to study it
thoroughly as a part of his job.
The problem is that if the compiler emits too many diagnostics
the important ones will go unnoticed, swallowed by the noise
of the unimportant ones.

That's what different diagnostic levels are for. If a programmer
explicitly asks for *all* possible diagnostics, then he is presumably
prepared to deal with some innocuous ones.
Note that Microsoft C, for instance will not diagnose this
even with the highest warning level.

This are the reasons behind the decision. Some people like
heathfield or becarisse use this as a "proof that lcc-win is
useless", etc. Their usual stuff. Note that lcc-win is not
just for pleasing pedants in comp.lang.c but it is useful
for doing REAL work. The objective is not to please
pedants here.

No one said lcc-win was "useless" or just for "pleasing pedants". This
thread developed because you claimed that lcc-win conforms to both C90
and C99 which is clearly not the case.

Regardless of conformance, one of the real advantages of HLLs is the
rigorous automated checking that is possible. People are prone to
errors and typos. A tool that catches them (even at the risk of some
false positives) is superior to one that has reduced ability in this
regard.

IME Intel's compiler has somewhat better diagnostics than even gcc. You
would do well to study it's behaviour and strive to emulate it. IMO of
course.
 
I

Ian Collins

jacob said:
Recently we had a discussion about the following code:

void f(long *lp) { *lp = 0; }
int main(void) { int i; f(&i); return i; }

lcc-win doesn't emit any diagnostic in normal mode, and doesn't
emit a diagnostic with the higher warning level.

It emits a diagnostic only in the highest warning level:

lcc -A -A foo.c

will diagnostic that with a warning.

Why?

Because under windows (32 and 64 bits) there is
absolutely no PRACTICAL difference between a
long and an int. They are completely equivalent types.
But they are incompatible types. I thought you'd made a Linux port of
the compiler? There you would have an issue.

Both Sun cc and gcc warn on their default settings.
The diagnostic would just add CLUTTER and NOISE to
the output of the compiler.

The problem is that if the compiler emits too many diagnostics
the important ones will go unnoticed, swallowed by the noise
of the unimportant ones.
Most shops have a "no warnings in the build" rule for that very reason.
It isn't hard to do.
 
I

Ian Collins

Richard said:
Ian Collins said:



Not if you only have to cater for one compiler, no. There's usually a way
of shutting most compilers up, for any given spurious warning.
Unfortunately, the way to shut one compiler up might well trigger a
warning under a different compiler. Compiling the same source base cleanly
under multiple implementations is not a trivial exercise.
In that case use minimum warning levels and lint.
 
K

Keith Thompson

jacob navia said:
Recently we had a discussion about the following code:

void f(long *lp) { *lp = 0; }
int main(void) { int i; f(&i); return i; }

Which clearly violates a constraint.
lcc-win doesn't emit any diagnostic in normal mode, and doesn't
emit a diagnostic with the higher warning level.

Out of curiosity, does lcc-win emit a diagnostic for this?

int main(void)
{
long obj = 42;
int *ptr = &obj;
return 0;
}

What about the equivalent using an assignment rather than an
initialization?
It emits a diagnostic only in the highest warning level:

lcc -A -A foo.c

will diagnostic that with a warning.

Ok.

A conforming compiler must issue a diagnostic for the above code. If
your documentation makes it clear that you have to invoke "lcc -A -A"
in order to conform to the standard, then there's no problem. I had
thought that "-ansic" was sufficient to cause lcc-win to (attempt to)
conform, but perhaps I was mistaken.

If you don't choose to produce a conforming compiler, that's entirely
up to you. I haven't chosen to produce a conforming C compiler
either.

If you don't produce a conforming compiler *and claim here that you
do*, you can expect to be called on it.
Why?

Because under windows (32 and 64 bits) there is
absolutely no PRACTICAL difference between a
long and an int. They are completely equivalent types.

They're distinct types in C. If that fact is of no interest to you, I
have to wonder why you participate in comp.lang.c.

As a practical matter, a programmer who writes a function with a
parameter of type long* and passes it a parameter of type int*, that's
a mistake. Even if int and long happen to have the same
representation, and even if portability to other systems is of no
concern, the code is confusing, and it would be improved by making the
parameter and argument types consistent.

I could easily make that kind of mistake myself. I would be upset if
my compiler chose to conceal the error from me.
The diagnostic would just add CLUTTER and NOISE to
the output of the compiler.

The problem is that if the compiler emits too many diagnostics
the important ones will go unnoticed, swallowed by the noise
of the unimportant ones.

Note that Microsoft C, for instance will not diagnose this
even with the highest warning level.

If that's true, then it's a bug in Microsoft C.
This are the reasons behind the decision. Some people like
heathfield or becarisse use this as a "proof that lcc-win is
useless", etc. Their usual stuff. Note that lcc-win is not
just for pleasing pedants in comp.lang.c but it is useful
for doing REAL work. The objective is not to please
pedants here.

Apparently the objective is not to conform to the standard either.
And that's just fine if you don't claim to conform to the standard.

But I wish you would make up your mind. Is conformance to the
standard important, or isn't it?
 
S

santosh

Keith said:
Which clearly violates a constraint.


Out of curiosity, does lcc-win emit a diagnostic for this?

int main(void)
{
long obj = 42;
int *ptr = &obj;
return 0;
}

What about the equivalent using an assignment rather than an
initialization?

It does (at least my copy of it). In both cases the diagnostic is:

Warning test.c: 5 assignment of pointer to long int to pointer to int

In addition:

Warning test.c: 4 ptr is assigned a value that is never used

is also emitted.

<snip>
 
S

Spiro Trikaliotis

Hello,

jacob said:
Recently we had a discussion about the following code:

void f(long *lp) { *lp = 0; }
int main(void) { int i; f(&i); return i; }
[...]

Note that Microsoft C, for instance will not diagnose this
even with the highest warning level.

This is not true. I just tried it with Visual C++ 6.0, all service packs
applied:

default settings: (warning level 3): No warning
incremented warning level to 4: No warning

warning level back to 3, but "disable language extensions" active:

C:\test\a.c(9) : warning C4133: 'function' : incompatible types - from 'int *' to 'long *'

This is exactly what I have expected.

I do not expect a compiler must emit the warning if it does not claim to
be conforming ("language extensions") - although, I would love it.
However, I expect it to emit these warnings if in compliant mode - and
MSVC6 does.

Note that this is MSVC6, which is ten years old.

Regards,
Spiro.

"Anybody who would spend considerable effort emulating a C64 is not
particularly sane to begin with; it is unreasonable to expect them to produce
sane software."
("asuffield" in http://forums.thedailywtf.com/forums/p/7199/134136.aspx)
 
J

Joachim Schmitz

Spiro said:
Hello,

jacob said:
Recently we had a discussion about the following code:

void f(long *lp) { *lp = 0; }
int main(void) { int i; f(&i); return i; }
[...]

Note that Microsoft C, for instance will not diagnose this
even with the highest warning level.

This is not true. I just tried it with Visual C++ 6.0, all service
packs
applied:

default settings: (warning level 3): No warning
incremented warning level to 4: No warning

warning level back to 3, but "disable language extensions" active:

C:\test\a.c(9) : warning C4133: 'function' : incompatible types -
from 'int *' to 'long *'

This is exactly what I have expected.
And the considerably younger VC 8.0, AKA Visual Studio 2005, is giving
exatly the same warning, down to warning level 1, as long as language
extension are disabled (i.e. working in conforming mode).

Bye, Jojo
 
J

jacob navia

Joachim said:
Spiro said:
Hello,

jacob said:
Recently we had a discussion about the following code:

void f(long *lp) { *lp = 0; }
int main(void) { int i; f(&i); return i; } [...]

Note that Microsoft C, for instance will not diagnose this
even with the highest warning level.
This is not true. I just tried it with Visual C++ 6.0, all service
packs
applied:

default settings: (warning level 3): No warning
incremented warning level to 4: No warning

warning level back to 3, but "disable language extensions" active:

C:\test\a.c(9) : warning C4133: 'function' : incompatible types -
from 'int *' to 'long *'

This is exactly what I have expected.
And the considerably younger VC 8.0, AKA Visual Studio 2005, is giving
exatly the same warning, down to warning level 1, as long as language
extension are disabled (i.e. working in conforming mode).

Bye, Jojo

I did not know that you have to disable language extensions
to get a warning.

Anyway, that obscure option matches lcc -A -A obscure option.
 
S

Spiro Trikaliotis

jacob said:
Joachim said:
Spiro Trikaliotis wrote: [...]
warning level back to 3, but "disable language extensions" active: [...]
This is exactly what I have expected.
And the considerably younger VC 8.0, AKA Visual Studio 2005, is giving
exatly the same warning, down to warning level 1, as long as language
extension are disabled (i.e. working in conforming mode).
[...]
I did not know that you have to disable language extensions
to get a warning.

Anyway, that obscure option matches lcc -A -A obscure option.

For me, "disable language extensions" matches something like "--ansi"
(or similar).

Regards,
Spiro.

"Anybody who would spend considerable effort emulating a C64 is not
particularly sane to begin with; it is unreasonable to expect them to produce
sane software."
("asuffield" in http://forums.thedailywtf.com/forums/p/7199/134136.aspx)
 
J

jacob navia

Eric said:
This is a difficult notion for assembly programmers to grasp:
They tend to think about "type" in the way the hardware does, so
the idea of distinct types with identical behavior seems to them
obfuscatory. Angels on pinheads, academic piffle, and so on.


Pedants love that.

"char is different from signed char and unsigned char. It is another
type".

"int and long are different types even if they are the same in some
implementations"

And so on.

Yes, how CLEVER, how WELL you have mastered the C language, incredible.

I am just an "assembly language programmer". Obviously for you they
are kind of thick heads that have "difficulties" grasping elementary
concepts like how many bugs can you fit in a pinhead.

Contrary to the pedants here that despise assembly and assembly
language programmers I write assembly every day. Even worst

o I generate assembly language from C input
o I assemble it
o I link it

Can you imagine that?

I *must* be a thick head then, obviously.
 
K

Kenneth Brody

jacob said:
Recently we had a discussion about the following code:

void f(long *lp) { *lp = 0; }
int main(void) { int i; f(&i); return i; }
[... No warning, because "int" and "long" are the same representation ...]
Note that Microsoft C, for instance will not diagnose this
even with the highest warning level.
[...]

Not quite. With "/W4", MSVC does emit this:

==========
C:\temp>cl /c /W4 usenet.c
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8804 for 80x86
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.

usenet.c
usenet.c(2) : warning C4057: 'function' : 'long *' differs in indirection to
slightly different base types from 'int *'

C:\temp>
==========

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:[email protected]>
 
K

Kenneth Brody

Richard said:
jacob navia said:


A diagnostic message is required for constraint violations and syntax
errors. If your implementation doesn't issue one, it doesn't conform to
the language spec.

If int and long have the exact same representation, has a constraint
violation actually occurred? (Not that I would call this good coding
practice, of course.)

What about:

void f(long *lp) { *lp = 0; }
typedef long foobar;
int main(void) { foobar i; f(&i); return i; }

You're now passing "pointer to foobar", not "pointer to long".

[...]

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:[email protected]>
 
J

Joachim Schmitz

Spiro said:
jacob said:
Joachim said:
Spiro Trikaliotis wrote: [...]
warning level back to 3, but "disable language extensions" active: [...]
This is exactly what I have expected.
And the considerably younger VC 8.0, AKA Visual Studio 2005, is
giving exatly the same warning, down to warning level 1, as long as
language extension are disabled (i.e. working in conforming mode).
[...]
I did not know that you have to disable language extensions
to get a warning.

Anyway, that obscure option matches lcc -A -A obscure option.

For me, "disable language extensions" matches something like "--ansi"
(or similar).
indeed, in the win-lcc case this would be -ansic, as far as I understood.

Bye, Jojo
 
J

Joachim Schmitz

jacob said:
Joachim said:
Spiro said:
Hello,

jacob navia wrote:

Recently we had a discussion about the following code:

void f(long *lp) { *lp = 0; }
int main(void) { int i; f(&i); return i; }
[...]

Note that Microsoft C, for instance will not diagnose this
even with the highest warning level.
This is not true. I just tried it with Visual C++ 6.0, all service
packs
applied:

default settings: (warning level 3): No warning
incremented warning level to 4: No warning

warning level back to 3, but "disable language extensions" active:

C:\test\a.c(9) : warning C4133: 'function' : incompatible types -
from 'int *' to 'long *'

This is exactly what I have expected.
And the considerably younger VC 8.0, AKA Visual Studio 2005, is
giving exatly the same warning, down to warning level 1, as long as
language extension are disabled (i.e. working in conforming mode).

Bye, Jojo

I did not know that you have to disable language extensions
to get a warning.
You have neen told about 'invoked in conforming mode' numerours times.
Disabling extensions is just that (or at least part of it)
Anyway, that obscure option matches lcc -A -A obscure option.
Nothing obscure about the documented /Za. lcc -A -A ist indeed obscure...

Bye, Jojo
 
B

Ben Bacarisse

jacob navia said:
Some people like
heathfield or becarisse use this as a "proof that lcc-win is
useless", etc.

For the record I did not say that. Please note that my name is
Bacarisse. Odd that you get the French name wrong.
Note that lcc-win is not
just for pleasing pedants in comp.lang.c but it is useful
for doing REAL work. The objective is not to please
pedants here.

On the off chance you care what I think: (a) I'd love lcc-win32 to be
C99. I want to be able to use C99 features in portable code and that
requires more implementations. For a while I though lcc-win32 might
get there. (b) I want errors such as the int/long type issue to be
diagnosed because it will usually be a bug in my program. I don't
write code that deliberately contains constrain violations. The more
strict the compiler is, the more bugs *of mine* it will catch early.
It has nothing to do with being pedantic.
 
I

Ian Collins

jacob said:
Pedants love that.

"char is different from signed char and unsigned char. It is another
type".

"int and long are different types even if they are the same in some
implementations"

And so on.

Yes, how CLEVER, how WELL you have mastered the C language, incredible.
Is that slapdash blinkered attitude typical of windows programmers?

What you consider pedantic most professional programmers would consider
attention to detail. Thank goodness NASA programmers don't share your
attitude.

C++ is more yet more strict, the example you posted is a syntax error to
a C++ compiler.
 
C

CBFalconer

Joachim said:
You have neen told about 'invoked in conforming mode' numerours
times. Disabling extensions is just that (or at least part of it)


Nothing obscure about the documented /Za. lcc -A -A ist indeed
obscure...

I think we can forgive Jacob for not knowing about the MS option.
What is not equally forbiddable is his simply ignoring the advice
about MS behaviour various users have posted here. Some people
would ask questions, rather than simply deny.
 
C

CBFalconer

Eric said:
jacob navia wrote:
.... snip ...


They are distinct types that happen (on this implementation)
to share the same underlying representation.

This is a difficult notion for assembly programmers to grasp:
They tend to think about "type" in the way the hardware does, so
the idea of distinct types with identical behavior seems to them
obfuscatory. Angels on pinheads, academic piffle, and so on.

I think this is easily covered for assember or compiler users. The
item specified as a 'long' is expected to handle values larger than
the minimum allowable value of INT_MAX. The item specified as an
'int' is not expected to handle such a size. These limits are not
contained in the compiler documentation, but require reading the
standard, or at least a portion thereof.
 

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,773
Messages
2,569,594
Members
45,121
Latest member
LowellMcGu
Top