473,383 Members | 1,997 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

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 1724
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.comwrites:
>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
Joachim Schmitz wrote:
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

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.
--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
Jul 14 '08 #11
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.
Since the diagnostic is required, it follows that using the
highest warning level is a prerequisite for operating the compiler
in a conforming mode.
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 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.

But the distinction is real, and also useful. Let me pose
a rhetorical question: If int and long are really the same, why
do programmers write `int' at some places and `long' at others?
Clearly the programmers who make the choices think there are --
or at least can be -- differences between int and long, and by
writing one or the other they express an intention about how they
want their variables to behave. To put the rhetorical question
even more crudely: If int and long are identical, why not just
eliminate `long' and flag it as an error?

Here's another, somewhat more abstract reason to pay attention
to type distinctions. To begin, we all know that `char' has the
same representation and behavior as `signed char' on some systems,
and as `unsigned char' on others. Yet even though `char' is "just
like" one or the other of these types, it is a type distinct from
both of them. By using plain `char', the programmer expresses a
preference that the machine use whichever type is "easier" for it
to deal with; the programmer does not need to commit to signed or
to unsigned and find that his code is unnecessarily slow on half
the machines that run it. That's why it is valuable to be able to
write `char' as distinct from `signed char' and `unsigned char',
even though it always behaves like one or the other. A distinction
that makes no difference on any one machine turns out to make a
difference when considering the wider universe of target machines.

Similar concerns motivate other types, too, which is why the
sizeof operator produces a size_t, why time() returns a time_t,
why sig_atomic_t exists, and so on. On any implementation you
can point at, these abstracted types (and others) are very likely
to be synonyms for various flavors of integers -- but for different
flavors on different systems. That's why portability is improved
by paying attention to type distinctions: They permit the programmer
to express his intentions to many platforms at once rather than to
just one at a time.
This are the reasons behind the decision. Some people like
heathfield or becarisse use this as a "proof that lcc-win is
useless", etc.
I don't recall seeing anyone describe lcc-win as "useless."
"Non-conforming," yes, but that's a different matter.
Note that lcc-win is not
just for pleasing pedants in comp.lang.c but it is useful
for doing REAL work.
It seems to me that "REAL" workers pay due attention to
portability, in light of the objectives of the project at hand.
A compiler that points out accidental strayings is helpful to
the programmers doing the REAL work, hence useful in that work.

--
Eric Sosman
es*****@ieee-dot-org.invalid
Jul 14 '08 #12
jacob navia schrieb:
Joachim Schmitz wrote:
>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)

--
Spiro R. Trikaliotis http://opencbm.sf.net/
http://www.trikaliotis.net/ http://www.viceteam.org/
Jul 14 '08 #13
Eric Sosman wrote:
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.
--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
Jul 14 '08 #14
jacob navia wrote:
Eric Sosman wrote:
> 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.
I've never said you have a thick head, not in this nor in
any other thread. Nor did I use the word "just" as in "mere"
or "only" to describe assembly language programmers; in fact,
I wrote "just" only three times altogether, none of them having
to do with programmers of any stripe.

What I wrote is that assembly language programmers have a
hard time understanding the importance of type, and I speculated
about the reason. That's my opinion, and by dismissing type as
pedantry you offer supporting evidence.
Contrary to the pedants here that despise assembly and assembly
language programmers
If you intend to include me among the despisers, you are
flat-out wrong. R-O-N-G, wrong.
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.
Not a thick head, but an extraordinarily thin skin.

--
Er*********@sun.com
Jul 14 '08 #15
Spiro Trikaliotis wrote:
jacob navia schrieb:
>Joachim Schmitz wrote:
>>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
Jul 14 '08 #16
jacob navia wrote:
Joachim Schmitz wrote:
>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


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
Jul 14 '08 #17
jacob navia <ja***@nospam.comwrites:
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.

--
Ben.
Jul 14 '08 #18
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; }
[... 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:Th*************@gmail.com>
Jul 14 '08 #19
Richard Heathfield wrote:
>
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.
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:Th*************@gmail.com>

Jul 14 '08 #20
Kenneth Brody wrote:
Richard Heathfield wrote:
>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; }
[...]
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?
Yes. 6.5.2.2p7 says the argument expressions are converted
"as if by assignment" to the types of the parameters. 6.5.16.1p1
gives constraints on assignment; the third bullet is the one that
applies here, and requires that the pointers point to compatible
types. 6.2.7 defines "compatible type;" the pair long*/int* does
not meet its definition. Therefore the 6.5.16.1p1 constraint is
violated, and a diagnostic is required.
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".
Unfortunately (IMHO), this one is not a constraint violation.
The typedef keyword does not actually introduce a new type, but
creates an alias for an existing type. So `foobar' *is* `long',
not a new type that happens to look like `long'.

--
Er*********@sun.com
Jul 14 '08 #21
Eric Sosman wrote:
[...] 6.5.16.1p1
gives constraints on assignment; the third bullet is the one that
applies here, and requires that the pointers point to compatible
types. 6.2.7 defines "compatible type;" the pair long*/int* does
not meet its definition. [...]
Sorry; I should have said "the pair long/int," without the
asterisks. long* and int* are in fact incompatible, but it's
the types they point to that are in question here.

--
Er*********@sun.com
Jul 14 '08 #22
jacob navia wrote:
Eric Sosman wrote:
> 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.
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.

--
Ian Collins.
Jul 14 '08 #23
Ian Collins <ia******@hotmail.comwrites:
[...]
C++ is more yet more strict, the example you posted is a syntax error to
a C++ compiler.
The example in question was:

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

In C, this has no syntax errors, but it does violate a constraint, so
a diagnostic message is required. (Since the standard doesn't
distinguish between diagnostic messages for syntax errors and
diagnostic messages for constraint violations, the effect is the
same.)

<OT>The situation in C++ is similar.</OT>

(I don't see how C++ is relevant here.)

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jul 14 '08 #24
Joachim Schmitz wrote:
jacob navia wrote:
>Joachim Schmitz wrote:
.... snip ...
>>
>>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.

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...
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.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
Jul 14 '08 #25
Eric Sosman wrote:
jacob navia wrote:
.... snip ...
>
>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 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.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
Jul 14 '08 #26
Kenneth Brody wrote:
jacob navia wrote:
.... snip ...
>
>Note that Microsoft C, for instance will not diagnose this
even with the highest warning level.
[...]

Not quite. With "/W4", MSVC does emit this:
In my experience (about 9 years old) using /W4 is impossible, since
MSVC then checks all its own system .h files, and spits out an
unholy mess of error/warning messages.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
Jul 14 '08 #27
jacob navia wrote, On 14/07/08 13:49:
Joachim Schmitz wrote:
>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).

I did not know that you have to disable language extensions
to get a warning.
How many compilers do you know of that conform to the standard by
default? I can't think of any and I am certain they are in a
considerable minority.
Anyway, that obscure option matches lcc -A -A obscure option.
No, in MSVC it is *not* an obscure option. It is an option clearly
visible in the GUI and described in the documentation. Based on reports
here (which you have not denied) you double -A is not described in your
documentation.
--
Flash Gordon
Jul 14 '08 #28
Ian Collins wrote, On 14/07/08 08:23:
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.
Or use maximum (or some balance) warning level and then justify the
deviation at the review. Where I used to work we had a rule of "no
warnings" *but* if you could justify at review a small number of
warnings this would be accepted.
--
Flash Gordon
Jul 14 '08 #29
On Jul 15, 9:35 am, Keith Thompson <ks...@mib.orgwrote:
Ian Collins <ian-n...@hotmail.comwrites:

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

The example in question was:

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

<OT>The situation in C++ is similar.</OT>

(I don't see how C++ is relevant here.)
It probably isn't. It's just one of my pet gripes about C: C isn't
strict enough on type matching. I think C should have moved more in
the C++ direction and required stricter type matching.

Ian.
Jul 14 '08 #30
CBFalconer said:
Kenneth Brody wrote:
>jacob navia wrote:
... snip ...
>>
>>Note that Microsoft C, for instance will not diagnose this
even with the highest warning level.
[...]

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

In my experience (about 9 years old) using /W4 is impossible, since
MSVC then checks all its own system .h files, and spits out an
unholy mess of error/warning messages.
In my experience, however, /W4 is perfectly practical as long as you're not
#including <windows.h- the only diagnostic message I recall for the
standard headers is for a syntax error in <math.h- a // "comment".

--
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 #31
Ian Collins wrote:
jacob navia wrote:
>Eric Sosman wrote:
>> 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.
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.
Details of no practical significance are crucial yes.
C++ is more yet more strict, the example you posted is a syntax error to
a C++ compiler.
If you like C++ then please go to the comp.lang.c++ group.
There is no point in contributing to this group.

In all the conversation I have had with you, the only thing that
clearly comes out of your messages is that C++ is far better than C.

OK. You are right. Then accept the consequences and go to that group.
--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
Jul 14 '08 #32
Ian Collins wrote:
jacob navia wrote:
.... snip ...
>
>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.
The last couple of days there was something in comp.arch.embedded
(I think - maybe it was here) about the fact that the last Mars
lander was programmed in C. I added something about the
requirement for good programmers, to do that. I can just envision
Jacob writing code for that system.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
Jul 14 '08 #33
jacob navia <ja***@nospam.comwrites:
[...]
Details of no practical significance are crucial yes.
So lcc-win doesn't issue a diagnostic when you pass an int* argument
to a function that expects a long*. You claim that, since int and
long happen to have the same representation, such a diagnostic is of
no practical significance (in spite of the fact that the standard
absolutely requires such a diagnostic for any conforming
implementation).

Why then does lcc-win issue a diagnostic when you assign an int* value
to a long* object, or use an int* value to initialize a long* object?

Specifically, of the three following programs:

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

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

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

why does lcc-win emit diagnostics for the second and third, but not
for the first?

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jul 15 '08 #34
On Jul 15, 11:05 am, jacob navia <ja...@nospam.comwrote:
Ian Collins wrote:
jacob navia wrote:
Eric Sosman wrote:
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.
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.

Details of no practical significance are crucial yes.
So standard conformance and portablity are of no practical
significance?
C++ is more yet more strict, the example you posted is a syntax error to
a C++ compiler.

In all the conversation I have had with you, the only thing that
clearly comes out of your messages is that C++ is far better than C.
Well it is in many ways (by design). But C is still C and sloppy
programming is sloppy programming in any language. I only mentioned C+
+ to illustrate that the compiler can and should help root out sloppy
practices.

Ian
Jul 15 '08 #35
On Mon, 14 Jul 2008 10:56:56 -0400, Kenneth Brody
<ke******@spamcop.netwrote in comp.lang.c:
Richard Heathfield wrote:

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.

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.)
Let's turn that question around and shake it up a little bit...

extern void char_func(char *cp);
extern void schr_func(signed char *sp);
extern void uchr_func(unsigned char *up);

int main(void)
{
char fred [] = "fred";
char_func(fred);
schr_func(fred);
uchr_func(fred);
return 0;
}

The types char, signed char, and unsigned char are three distinct
types, even though two of these types are guaranteed to be the same.

Pointers to these three types are not compatible without a cast.

Should a compiler only issue a diagnostic for the constraint violation
of the pointer to the (un)signed type that is not compatible with
"plain" char?

What about if I invoke the compiler with an option that many have, to
changed the signedness of "plain" char to the opposite of its default
value?
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".
No, you are passing a pointer to long. There is no such thing as a
"foobar". The identifier "foobar" is an alias for the type "(signed)
long (int)", it is not a type in and of itself.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
Jul 15 '08 #36
Jack Klein <ja*******@spamcop.netwrites:
[...]
The types char, signed char, and unsigned char are three distinct
types, even though two of these types are guaranteed to be the same.
[...]

To be just a trifle more precise, two of them are guaranteed to have
the same range, representation, and behavior. They remain, as you
said, three distinct types.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jul 15 '08 #37
On 15 Jul, 00:05, jacob navia <ja...@nospam.comwrote:
Ian Collins wrote:
jacob navia wrote:
Eric Sosman wrote:
>* * 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.
you know if you tried listening to people and thinking about
what they say you might learn something interesting.

Let's take it in gentle steps. C provides a long type and an int
type. Why? Sometimes a programmer (eg. me) selects int in other cases
long can you speculate why he (ie. me) might do that?

One of the things I worry about is portability. Not because of
academic piffle but becuase of real world experience of programs
outliving their hardware. Software written in the 80's and 90's
is still running. And still doing useful work. A while ago we
(the programming community) had the horrors of moving from 16-bit
to 32-bit. Now we face 32-bit to 64-bit. People will store
addresses in ints or longs. People will use those "spare bits"
in the 24-bit colour type.

One of the nice thinsg about C is you *can* write portable
software. I'm porting old sun stuff to linux at the moment.
A program I've worked on has moved from HP-UX to Windows.
"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"
*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?
no
What you consider pedantic most professional programmers would consider
attention to detail. *Thank goodness NASA programmers don't share your
attitude.

Details of no practical significance are crucial yes.
I don't think NASA programmers can be accused of being impractical...

<snip>

--
Nick Keighley

"There are two ways of constructing a software design: One way is to
make it so simple that there are obviously no deficiencies, and the
other way is to make it so complicated that there are no obvious
deficiencies. The first method is far more difficult."
-- C.A.R. Hoare
Jul 15 '08 #38
Flash Gordon wrote:
<snip>
How many compilers do you know of that conform to the standard by
default? I can't think of any and I am certain they are in a
considerable minority.
I know of one. It is called c89 and runs on NonStop Kernel (a propriatary
OS). There you have to switch on extensions
(-Wextensions, -Wallow_cplusplus_comments, -Wc99lite etc.)

Bye, Jojo
Jul 15 '08 #39
jacob navia <ja***@nospam.comwrote:
[in re. not diagnosing certain mismatches between int and long]
>
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.
Unless you're interested in porting your code to an environment where
they *aren't* completely equivalent types. In that case, you really
*do* want to know that you've screwed up your code.

How seriously to take such mismatches is an engineering decision that
each implementor needs to make based on their own environment and
customer base. Some implementors consider it an error by default,
others warn about it by default, others require special options before
it is diagnosed. In my opinion, it would be better if lcc-win diagnosed
it at a lower warning level than it currently does, but your decision
not to is entirely reasonable, too.
--
Larry Jones

It's not denial. I'm just very selective about the reality I accept.
-- Calvin
Jul 15 '08 #40

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

Similar topics

0
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...
2
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...
7
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...
3
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...
8
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...
2
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
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...
2
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...
0
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 =...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.