Is this legal ?

R

Richard Heathfield

jacob navia said:
Keith Thompson wrote:


The problem is that all windows header files use this. I DID emit an
error for this, but people complained that then you could NOT
compile a windows program in conforming mode, what made the
conforming mode useless for all practical purposes.

Then, I took out the error and made this exception. I do not
see any way out of this dilemma.

So lcc-win32 has no conforming mode? Interesting. So it's not a C compiler
after all.
 
J

jacob navia

Richard said:
jacob navia said:




So lcc-win32 has no conforming mode? Interesting. So it's not a C compiler
after all.

I prefer keeping the conforming mode for windows programs
than making a 100% conforming mode that can't be used in
practice and is only useful to satisfy the
requirements of the few "regulars" in comp.lang.c.
 
J

jacob navia

jacob said:
I prefer keeping the conforming mode for windows programs
than making a 100% conforming mode that can't be used in
practice and is only useful to satisfy the
requirements of the few "regulars" in comp.lang.c.

P.S. The same problem appears with the _stdcall extension
and the windows headers. _stdcall WILL be accepted in
conforming mode.
 
S

Skarmander

jacob said:
The problem is that all windows header files use this. I DID emit an
error for this, but people complained that then you could NOT
compile a windows program in conforming mode, what made the
conforming mode useless for all practical purposes.

Then, I took out the error and made this exception. I do not
see any way out of this dilemma.
The canonical way of approaching this is by inserting compiler magic into
the header which will turn on extensions without triggering errors, but only
for that header -- this is how C library headers ensure they compile no
matter how the compiler's invoked.

Unfortunately, although Win32 can be said to constitute a platform, the
Win32 headers themselves are often third-party, so this technique may not
always be usable.

The correct solution then, however, is simply to *not compile Win32
programs* in conforming mode. Your claim that this makes conforming mode
useless puts the cart before the horse: it's Win32's fault for forcing the
compiler to be put in a non-conforming mode, not strictly conforming C's
fault that you can't write Win32 programs in it. You can't have your cake
and eat it too.

What you are offering your users is an "almost conforming" mode, which is
fine, but pretending that this is actually the conforming mode when you
don't have one is disingenuous.

S.
 
J

jacob navia

Skarmander said:
The canonical way of approaching this is by inserting compiler magic
into the header which will turn on extensions without triggering errors,
but only for that header -- this is how C library headers ensure they
compile no matter how the compiler's invoked.

Unfortunately, although Win32 can be said to constitute a platform, the
Win32 headers themselves are often third-party, so this technique may
not always be usable.

The correct solution then, however, is simply to *not compile Win32
programs* in conforming mode. Your claim that this makes conforming mode
useless puts the cart before the horse: it's Win32's fault for forcing
the compiler to be put in a non-conforming mode, not strictly conforming
C's fault that you can't write Win32 programs in it. You can't have your
cake and eat it too.

What you are offering your users is an "almost conforming" mode, which
is fine, but pretending that this is actually the conforming mode when
you don't have one is disingenuous.

S.

Well I could add a

-pedantic

flag like another well known compiler...

Maybe that is the solution. You would have

-ansic (conforming except _stdcall and anonymous structures)

-pedantic (100% heathfield compatible)
 
C

CBFalconer

jacob said:
The algorithm is simple:

It requires that all field names (at any depths) are UNIQUE,
so your example will NOT work. The compiler will start a depth first
search in the whole nested structures with a field for that
name, and if it finds it it will automatically generate the
path to it.

I have the idea of this extensions from the Plan9 compiler
by Dennis Ritchie.

Which, in turn, is basically what Pascal has done for roughly the
past 40 years. It is still not legal C, and to suggest that it is
does a disservice to all.
 
K

Keith Thompson

jacob navia said:
The problem is that all windows header files use this. I DID emit an
error for this, but people complained that then you could NOT
compile a windows program in conforming mode, what made the
conforming mode useless for all practical purposes.

Then, I took out the error and made this exception. I do not
see any way out of this dilemma.

So lcc-win32's "conforming mode" is not conforming.

(It can't recognize when it's processing a Windows header file?)
 
C

CBFalconer

jacob said:
Richard Heathfield wrote:
.... snip ...

I prefer keeping the conforming mode for windows programs
than making a 100% conforming mode that can't be used in
practice and is only useful to satisfy the
requirements of the few "regulars" in comp.lang.c.

Since it only compiles Navia-C, and cannot detect errors in C
source code, it should never even be mentioned on c.l.c. You
should consider taking your comments to a Windows newsgroup, where
they might be topical.
 
J

jacob navia

Keith said:
jacob navia said:
Keith said:
jacob navia <[email protected]> writes:
[...]
union {
struct{
int a;
int b;
};
struct{
float c;
};
}un;

int main(void)
{

un.a = 1;
return 0;
}

lcc-win32 doesn't accept this code in conforming mode, does it?

The problem is that all windows header files use this. I DID emit an
error for this, but people complained that then you could NOT
compile a windows program in conforming mode, what made the
conforming mode useless for all practical purposes.

Then, I took out the error and made this exception. I do not
see any way out of this dilemma.


So lcc-win32's "conforming mode" is not conforming.

(It can't recognize when it's processing a Windows header file?)

No it can't because they could have *any* name.

I have just introduced a

-pedantic

option that will be 100% ped^h^h^h conforming.
:)
 
R

Richard Bos

The subject of the quetion was answered with my FIRST sentence:

"This is not strictly valid C".

And had you left it at that, you would have been almost correct.

But no, you had to advertise your broken, not even remotely C pet
project again. If you could learn not to do that, you might even grow up
to be a man some day.

Richard
 
R

Racaille

Spiros said:
How will the compiler react to the following ?

union {
struct{
int a;
int b;
};
struct{
float a;
float b;
};
}un;

that extension originates in the plan9 compiler, and
was adopted (bastardized & with many limitations)
first by MSVC, then by gcc.

it's actually a very useful extensions; you can do with that
everything you can do with inheritance in C++, and more.

in this case, unlike gcc, the plan9 compiler will complain about
'ambiguous structure element' and give up if you try to access
either un.a or un.b.
 
J

jacob navia

Richard said:
And had you left it at that, you would have been almost correct.

But no, you had to advertise your broken, not even remotely C pet
project again. If you could learn not to do that, you might even grow up
to be a man some day.

Richard

I am "not a man"...

GOSH !!!

My virility depends on the conforming mode of my
compiler system :)

Mr Bos, you are A MAN!!!

I would never doubt it, even if you use a castrated
C compiler that can't do anything else than ISO C.

jacob
 
J

jacob navia

Racaille said:
that extension originates in the plan9 compiler, and
was adopted (bastardized & with many limitations)
first by MSVC, then by gcc.

it's actually a very useful extensions; you can do with that
everything you can do with inheritance in C++, and more.

in this case, unlike gcc, the plan9 compiler will complain about
'ambiguous structure element' and give up if you try to access
either un.a or un.b.

Salut Racaille!

I have followed exactly the same behavior as that compiler.

jacob

P.S. lcc-win32 est a Villetaneuse, 93430.
 
S

Skarmander

jacob said:
Keith Thompson wrote:

No it can't because they could have *any* name.
Not true. The Win32 API requires headers to have certain names, just like
the C library does.

In particular, windef.h must exist, and any program that #includes
<windows.h> will pull in <windef.h> very early on, which will #define WIN32
if the user hasn't already done so. User programs are not expected to
include this file directly (and if they do they presumably don't care about
conformity).

Checking for this would be a fairly reliable way of detecting a Win32
header. Of course, you do need to invest a bit of work to get the
compiler/preprocessor to recognize such an include chain, and you must take
care not to trigger on just any old windef.h (it would be sufficient to
check if WIN32 is defined after windef.h has been preprocessed).

Failing that, GCC (rather MinGW) uses its own copies of the Win32 headers
with "#pragma GCC system_header" to invoke a non-conforming mode for just
those headers, an approach which is even more reliable, though it requires
you to distribute your own headers, which is not attractive.

Failing *that*, you could have your compiler differentiate between system
header includes and just any old includes based on file system path and
options, so that it knows when it's reading such a header file and should
invoke non-conforming mode.

It's useful to have some sort of mechanism for this anyway, because it
allows you to write system headers without worrying about what options the
user has set that might affect compilation.

S.
 
J

jacob navia

I have added a -pedantic option
that will solve this problem.

With that option, _stdcall, and anonymous structures are
forbidden. No windows programs then. But then, that is
no longer *my* problem :)
 
?

=?ISO-8859-1?Q?=22Nils_O=2E_Sel=E5sdal=22?=

jacob said:
union {
struct{
int a;
int b;
};
struct{
float c;
};
}un;

int main(void)
{

un.a = 1;
return 0;
}

K. Thompson implemented this in his "C" compiler
for Plan 9 too, btw :)
 
F

Frederick Gotham

jacob navia posted:
It will complain at the point of the declaration.


At which point, I'd like to complain about the lack of quote snippage being
undertaken by the two of you.
 
S

Spiros Bousbouras

Frederick said:
jacob navia posted:



At which point, I'd like to complain about the lack of quote snippage being
undertaken by the two of you.

Jacob and Navia are just one person :-D
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,434
Messages
2,571,685
Members
48,796
Latest member
Greg L.

Latest Threads

Top