473,587 Members | 2,443 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

When to emit diagnistics

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.
--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
Jul 14 '08 #1
39 1744
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; }

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
Jul 14 '08 #2
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; }

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.

Jul 14 '08 #3
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; }

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.
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.
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.
Syntax errors and constraint violations are pretty important.
>
Note that Microsoft C, for instance will not diagnose this
even with the highest warning level.
Liar. When you first claimed this, it was reasonable to assume you were
mistaken. But after you claimed it three times, I checked it and told you
"MSVC diagnoses this error properly when invoked in conforming mode", and
you replied "and lcc-win also", in an article timestamped 12 minutes or so
before your "When to emit diagnistics" article. So you knew and accepted
that Microsoft C does indeed diagnose this error, which makes you a liar
for pretending that it doesn't.
This are the reasons behind the decision. Some people like
heathfield or becarisse use this as a "proof that lcc-win is
useless", etc.
Liar. I have never claimed that lcc-win is useless. I *have* claimed that
it isn't a C compiler, and you seem to agree, since you don't appear to
claim either C90 or C99 conformance for it.
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.
If you want to get real work done, use a compiler that implements the
language it claims to implement.

--
Richard Heathfield <http://www.cpax.org.uk >
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Jul 14 '08 #4
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; }

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.

--
Ian Collins.
Jul 14 '08 #5
Ian Collins said:

<snip>
Most shops have a "no warnings in the build" rule for that very reason.
It isn't hard to do.
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.

--
Richard Heathfield <http://www.cpax.org.uk >
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Jul 14 '08 #6
Richard Heathfield wrote:
Ian Collins said:

<snip>
>Most shops have a "no warnings in the build" rule for that very reason.
It isn't hard to do.

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.

--
Ian Collins.
Jul 14 '08 #7
Keith Thompson wrote:
jacob navia <ja***@nospam.c omwrites:
>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 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>

Jul 14 '08 #8
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.

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)

--
Spiro R. Trikaliotis http://opencbm.sf.net/
http://www.trikaliotis.net/ http://www.viceteam.org/
Jul 14 '08 #9
Spiro Trikaliotis wrote:
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
Jul 14 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2176
by: Nigel Sampson | last post by:
ey all, I'm in the process of creating a method of tracking whenever an objects properties are changed. Since its not possible to alter existing types I decided to used a proxy generated using Reflection.Emit which inherits from the object needed Person p = (Person)ProxyBuilder.Construct(typeof(Person));
2
5179
by: DEK | last post by:
I'm creating a dynamic assembly which has one type with one constructor, the type inherits a base class Season, which is in the current assembly. I am trying to emit a constructor which simply calls the base constructor with the 4 args passed in, but I get this error Message at the second last line of the method CreateSeason (Marked with <<<<<) An unhandled exception of type 'System.MissingMethodException' occurred in mscorlib.dll ...
7
9948
by: Mark Miller | last post by:
I am using Reflection.Emit to dynamically build a class. A method of the class to be built requires a Parameter of type "Type". But I don't know how to use Emit to pass a call of "typeof()" to the method. The method could look like this: public void myDynamicMethod(Type type){ //.....do something with the Type passed in....... }
3
2510
by: John Arthur | last post by:
Hi, I am reading about Reflection.Emit and I can't really imagine a real situation where I can use this. Can someone give me an example that can't be done without Reflection or an example of something that If done with Reflection.Emit will be a lot faster or something sensible. I will really appreciate your help. Thanks : John Arthur
8
2533
by: Eyeawanda Pondicherry | last post by:
I have put some code together that creates an enum dynamically from some database values. The enum can be read perfectly by an application that references the dynamically generated dll. If I /emit/ a new version of the assembly, and start the application again, the new values will appear for the enum. However, suppose I want the application to remain in a running state.
2
3627
by: Luis Arvayo | last post by:
Hi, In c#, I need to dynamically create types at runtime that will consist of the following: - inherits from a given interface - will have a constructor with an int argument
1
1430
by: John | last post by:
I am trying to figure out how to translate the following CIL call into an Emit statement. In CIL it is: IL_004c: callvirt instance class System.Data.DataRow System.Data.DataRowCollection::get_Item(int32) The C# equivilant is as follows: MyDataRowCollection;
2
4475
by: joasi | last post by:
Hi, I am working in C# with an Object / Relational Database mapping framework, where I want to generate method calls based on string representation of the call signature. I have used reflection and Method-/Field-/PropertyInfo invokation to do this, but now I want to make the calls faster by using Emit and DynamicMethods I am now trying to create a factory method that creates a dynamic method as a "wrapper" around a method call with no...
0
1653
by: =?Utf-8?B?QXJ0dXJvIE1hcnRpbmV6?= | last post by:
I've been looking everywhere on how to call AddRange Method of a List<myClassfield in Reflection.Emit My code goes like this MethodInfo method = typeof(List<>).MakeGenericType(typeof(myClass)).GetMethod("AddRange", BindingFlags.Instance | BindingFlags.Public, null, new Type { typeof(IEnumerable<>).MakeGenericType(typeof(myClass)) }, null)); and then the implementation
0
7924
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7854
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8219
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
7978
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8221
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5395
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3845
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3882
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1455
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.