PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.c > // comments
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
// comments

Réponse
 
LinkBack Outils de la discussion
Vieux 27/04/2008, 00h27   #1
jacob navia
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut // comments

Recently we had poor Mr "teapot" that was horrified at the heresy
of lcc-win of accepting // comments.

C is a nice language, and you can do anything with it, inclusive a
program that transforms // comments into well behaved /* ... */
ones...

------------------------------------------------cut here

/*
This program reads a C source file and writes it modified to stdout
All // comments will be replaced by / * ... * / comments, to easy the
porting to old environments or to post it in usenet, where
// comments can be broken in several lines, and messed up.
*/

#include <stdio.h>
#include <stdlib.h>

/* This function reads a character and writes it to stdout */
static int Fgetc(FILE *f)
{
int c = fgetc(f);
if (c != EOF)
putchar(c);
return c;

}

/* This function skips strings */
static int ParseString(FILE *f)
{
int c = Fgetc(f);
while (c != EOF && c != '"') {
if (c == '\\')
c = Fgetc(f);
if (c != EOF)
c = Fgetc(f);
}
if (c == '"')
c = Fgetc(f);
return c;
}

/* Skips multi-line comments */
static int ParseComment(FILE *f)
{
int c = Fgetc(f);

while (1) {
while (c != '*') {
c = Fgetc(f);
if (c == EOF)
return EOF;
}
c = Fgetc(f);
if (c == '/')
break;
}
return Fgetc(f);

}

/* Skips // comments. Note that we use fgetc here and NOT Fgetc */
/* since we want to modify the output before gets echoed */
static int ParseCppComment(FILE *f)
{
int c = fgetc(f);

while (c != EOF && c != '\n') {
putchar(c);
c = fgetc(f);
if (c == '*') {
c = fgetc(f);
if (c == '/') {
c = fgetc(f);
putchar(' ');
}
else {
putchar('*');
}
}
}
if (c == '\n') {
puts(" */");
c = Fgetc(f);
}
return c;

}

/* Checks if a comment is followed after a '/' char */
static int CheckComment(int c,FILE *f)
{
if (c == '/') {
c = fgetc(f);
if (c == '*') {
putchar('*');
c = ParseComment(f);
}
else if (c == '/') {
putchar('*');
c = ParseCppComment(f);
}
else {
putchar(c);
c = Fgetc(f);
}
}
return c;

}

/* Skips chars between simple quotes */
static int ParseQuotedChar(FILE *f)
{
int c = Fgetc(f);
while (c != EOF && c != '\'') {
if (c == '\\')
c = Fgetc(f);
if (c != EOF)
c = Fgetc(f);
}
if (c == '\'')
c = Fgetc(f);
return c;

}

int main(int argc,char *argv[])
{
FILE *f;
int c;
if (argc == 1) {
puts("Usage: give an input file name. Writes to stdout");
return EXIT_FAILURE;
}
f = fopen(argv[1],"r");
if (f == NULL) {
puts("Can't find the input file");
return EXIT_FAILURE;
}
c = Fgetc(f);
while (c != EOF) {
/* Note that each of the switches must advance the character */
/* read so that we avoid an infinite loop. */
switch (c) {
case '"':
c = ParseString(f);
break;
case '/':
c = CheckComment(c,f);
break;
case '\'':
c = ParseQuotedChar(f);
break;
default:
c = Fgetc(f);
}
}
fclose(f);
return 0;

}

----------------------------------------------------------cut here

Note that trigraphs are not supported. Homework: Add that feature

Compiled with lcc-win, this program makes only 3 616 bytes. C is
an efficient language.

P.S. Note that I have avoided printf... If you add printf the size
will be a HUGE 37K.

--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
  Réponse avec citation
Vieux 27/04/2008, 02h22   #2
Ben Bacarisse
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: // comments

jacob navia <jacob@nospam.com> writes:

> Recently we had poor Mr "teapot" that was horrified at the heresy
> of lcc-win of accepting // comments.


Can you clear up the question of what the -ansi89 flag is intended to
do? Your compiler is allowed to accept any extensions it likes and to
reject and conforming C90 programs it wishes to *unless* you claim that
lc -ansi89 is intended to be a conforming C90 implementation. What is
the purpose of -ansi89?

> C is a nice language, and you can do anything with it, inclusive a
> program that transforms // comments into well behaved /* ... */
> ones...


How do you do that with:

int main(void) { return 1//* divide? */2; }

Is this a valid C90 program or an incorrect C90 one that has a //
comment int it?

<snip program>
> Note that trigraphs are not supported. Homework: Add that feature


I also does not treat multi-line // comments correctly.

--
Ben.
  Réponse avec citation
Vieux 27/04/2008, 07h08   #3
Richard Heathfield
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: // comments

jacob navia said:

> Recently we had poor Mr "teapot" that was horrified at the heresy
> of lcc-win of accepting // comments.


It is surely not too surprising that at least one user is horrified by the
idea that a supposedly conforming C90 implementation fails to produce a
diagnostic message for a syntax error. We knew lcc-win32 didn't conform to
C99. Now it appears it doesn't appear to conform to C90 either.

Does it at least have a K&R C mode? If not, it would seem that it isn't
actually a C compiler after all, and is therefore off-topic in
comp.lang.c.

> C is a nice language, and you can do anything with it, inclusive a
> program that transforms // comments into well behaved /* ... */
> ones...


....and fails not only on trigraphs (as you pointed out) but also on the
following input:

/\
/ double-slash comment with line-splice

--
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
  Réponse avec citation
Vieux 27/04/2008, 08h11   #4
jacob navia
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: // comments

Ben Bacarisse wrote:
> jacob navia <jacob@nospam.com> writes:
>
>> Recently we had poor Mr "teapot" that was horrified at the heresy
>> of lcc-win of accepting // comments.

>
> Can you clear up the question of what the -ansi89 flag is intended to
> do? Your compiler is allowed to accept any extensions it likes and to
> reject and conforming C90 programs it wishes to *unless* you claim that
> lc -ansi89 is intended to be a conforming C90 implementation. What is
> the purpose of -ansi89?
>


-ansi89 was implemented to the wishes of a paying customer. They wanted
a compiler to that standard, and I implemented it for them. The usage of
that flag is to disable most C99 stuff.

Note that many compilers at the C89 level accept // comments, for instance
Microsoft compilers

--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
  Réponse avec citation
Vieux 27/04/2008, 08h25   #5
Keith Thompson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: // comments

jacob navia <jacob@nospam.com> writes:
> Ben Bacarisse wrote:
>> jacob navia <jacob@nospam.com> writes:
>>
>>> Recently we had poor Mr "teapot" that was horrified at the heresy
>>> of lcc-win of accepting // comments.

>>
>> Can you clear up the question of what the -ansi89 flag is intended to
>> do? Your compiler is allowed to accept any extensions it likes and to
>> reject and conforming C90 programs it wishes to *unless* you claim that
>> lc -ansi89 is intended to be a conforming C90 implementation. What is
>> the purpose of -ansi89?
>>

>
> -ansi89 was implemented to the wishes of a paying customer. They wanted
> a compiler to that standard, and I implemented it for them. The usage of
> that flag is to disable most C99 stuff.


If your paying customer is satisfied with that, then that's fine.
However, the ANSI C89 standard (or equivalently the ISO C90 standard)
requires a diagnostic for a "//" comment (except in the rare cases
where it can be a legal C89 construct, such as a division operator
immediately followed by a comment). If your compiler doesn't issue a
diagnostic for a "//" comment, then it's not a 100% conforming C89
compiler. I hope that your documentation makes that clear.

Since it's easy enough to implement full C89 conformance in this area
by issuing a warning, perhaps just on the first occurrence in a
translation unit, I fail to understand why you wouldn't go ahead and
do so, but that's up to you.

> Note that many compilers at the C89 level accept // comments, for instance
> Microsoft compilers


Then my comment applies to them as well.

(If you perceive a personal attack in the above, or an attack on
lcc-win, or on C99, or on // comments, then you've misunderstood me.
Again.)

--
Keith Thompson (The_Other_Keith) <kst-u@mib.org>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
  Réponse avec citation
Vieux 27/04/2008, 09h22   #6
Richard Heathfield
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: // comments

Keith Thompson said:

> jacob navia <jacob@nospam.com> writes:


<snip>

>> Note that many compilers at the C89 level accept // comments,


If they are invoked in conforming mode, they *must* diagnose syntax errors.

>> for instance Microsoft compilers

>
> Then my comment applies to them as well.


When invoked in conforming mode, Microsoft C (or at least my copy of it)
issues the necessary diagnostic message if you use // in an erroneous
syntactical context.

<snip>

--
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
  Réponse avec citation
Vieux 27/04/2008, 09h59   #7
jacob navia
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: // comments

Richard Heathfield wrote:
> Keith Thompson said:
>
>> jacob navia <jacob@nospam.com> writes:

>
> <snip>
>
>>> Note that many compilers at the C89 level accept // comments,

>
> If they are invoked in conforming mode, they *must* diagnose syntax errors.
>


Maybe. If they do not, please use another compiler.

>>> for instance Microsoft compilers

>> Then my comment applies to them as well.

>
> When invoked in conforming mode, Microsoft C (or at least my copy of it)
> issues the necessary diagnostic message if you use // in an erroneous
> syntactical context.
>



D:\lcc\mc71\test>type tt.c
// aaaaa

D:\lcc\mc71\test>cl -W4 tt.c
Microsoft (R) C/C++ Optimizing Compiler Version 14.00.50727.762 for x64
Copyright (C) Microsoft Corporation. All rights reserved.

tt.c
tt.c(2) : warning C4206: nonstandard extension used : translation unit
is empty

Of course your version dates from 1991... Always the same word games,
half truths, etc. Pure regulars BS.

--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
  Réponse avec citation
Vieux 27/04/2008, 10h30   #8
vippstar@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: // comments

On Apr 27, 1:27 am, jacob navia <ja...@nospam.com> wrote:
> Recently we had poor Mr "teapot" that was horrified at the heresy
> of lcc-win of accepting // comments.

You seem horrified too. Or horrifying.
> C is a nice language, and you can do anything with it, inclusive a
> program that transforms // comments into well behaved /* ... */
> ones...

Actually, you cannot, at least not correctly. It's impossible to guess
the intend of the programmer in:
int main(void) { return 1//* divide? */2; }
As noted by Mr Bacarisse (but I have seen that example in other places
too)
<snip code>
>
> Note that trigraphs are not supported. Homework: Add that feature

Nor digraphs.
> Compiled with lcc-win, this program makes only 3 616 bytes. C is
> an efficient language.

I think what you're trying to say here is that lcc-win is efficient,
and not C. A language cannot be efficient, not in that sense.
> P.S. Note that I have avoided printf... If you add printf the size
> will be a HUGE 37K.

Maybe your compiler is not that efficient then (or maybe you did not
mention how you linked the lib).
Here with gcc I get 8K with no optimizations (using or not using
printf).
I wouldn't expect from someone who complains about "the regulars"
mentioning old systems to prove him wrong, to actually mention 37K as
a "HUGE" size. 37K is _nothing_ in a modern computer.
  Réponse avec citation
Vieux 27/04/2008, 11h26   #9
Flash Gordon
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: // comments

jacob navia wrote, On 27/04/08 08:59:
> Richard Heathfield wrote:
>> Keith Thompson said:
>>
>>> jacob navia <jacob@nospam.com> writes:

>>
>> <snip>
>>
>>>> Note that many compilers at the C89 level accept // comments,

>>
>> If they are invoked in conforming mode, they *must* diagnose syntax
>> errors.

>
> Maybe. If they do not, please use another compiler.


If you state that -ansi89 does *not* mean conformance to C89 (or C90 or
C95) then as has already been stated it is allowed to accept whatever
you want. If I was one of your paying customers I would not be happy,
but I'm not.

>>>> for instance Microsoft compilers
>>> Then my comment applies to them as well.

>>
>> When invoked in conforming mode, Microsoft C (or at least my copy of
>> it) issues the necessary diagnostic message if you use // in an
>> erroneous syntactical context.

>
> D:\lcc\mc71\test>type tt.c
> // aaaaa
>
> D:\lcc\mc71\test>cl -W4 tt.c
> Microsoft (R) C/C++ Optimizing Compiler Version 14.00.50727.762 for x64
> Copyright (C) Microsoft Corporation. All rights reserved.
>
> tt.c
> tt.c(2) : warning C4206: nonstandard extension used : translation unit
> is empty
>
> Of course your version dates from 1991... Always the same word games,
> half truths, etc. Pure regulars BS.


Not at all. You have just demonstrated that what Richard said is true
for the version you have as well. The compiler emitted a diagnostic.
There is no requirement for it to produce an error or abort the
translation. I have already posted saying that all you have to do is
detect it and issue a warning, as has Keith.
--
Flash Gordon
  Réponse avec citation
Vieux 27/04/2008, 12h05   #10
jacob navia
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: // comments

Flash Gordon wrote:
> jacob navia wrote, On 27/04/08 08:59:
>> Richard Heathfield wrote:
>>> When invoked in conforming mode, Microsoft C (or at least my copy of
>>> it) issues the necessary diagnostic message if you use // in an
>>> erroneous syntactical context.

>>
>> D:\lcc\mc71\test>type tt.c
>> // aaaaa
>>
>> D:\lcc\mc71\test>cl -W4 tt.c
>> Microsoft (R) C/C++ Optimizing Compiler Version 14.00.50727.762 for x64
>> Copyright (C) Microsoft Corporation. All rights reserved.
>>
>> tt.c
>> tt.c(2) : warning C4206: nonstandard extension used : translation unit
>> is empty
>>
>> Of course your version dates from 1991... Always the same word games,
>> half truths, etc. Pure regulars BS.

>
> Not at all. You have just demonstrated that what Richard said is true
> for the version you have as well. The compiler emitted a diagnostic.
> There is no requirement for it to produce an error or abort the
> translation. I have already posted saying that all you have to do is
> detect it and issue a warning, as has Keith.


word games, word games
// aaaaaaa
int a=0;

Now, cl doesn't give any warning:
D:\lcc\mc71\test>cl -W4 -c tt.c
Microsoft (R) C/C++ Optimizing Compiler Version 14.00.50727.762 for x6
Copyright (C) Microsoft Corporation. All rights reserved.

tt.c

D:\lcc\mc71\test>

WORD GAMES as always.

--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
  Réponse avec citation
Vieux 27/04/2008, 12h22   #11
santosh
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: // comments

jacob navia wrote:

> Flash Gordon wrote:
>> jacob navia wrote, On 27/04/08 08:59:
>>> Richard Heathfield wrote:
>>>> When invoked in conforming mode, Microsoft C (or at least my copy
>>>> of it) issues the necessary diagnostic message if you use // in an
>>>> erroneous syntactical context.
>>>
>>> D:\lcc\mc71\test>type tt.c
>>> // aaaaa
>>>
>>> D:\lcc\mc71\test>cl -W4 tt.c
>>> Microsoft (R) C/C++ Optimizing Compiler Version 14.00.50727.762 for
>>> x64
>>> Copyright (C) Microsoft Corporation. All rights reserved.
>>>
>>> tt.c
>>> tt.c(2) : warning C4206: nonstandard extension used : translation
>>> unit is empty
>>>
>>> Of course your version dates from 1991... Always the same word
>>> games, half truths, etc. Pure regulars BS.

>>
>> Not at all. You have just demonstrated that what Richard said is true
>> for the version you have as well. The compiler emitted a diagnostic.
>> There is no requirement for it to produce an error or abort the
>> translation. I have already posted saying that all you have to do is
>> detect it and issue a warning, as has Keith.

>
> word games, word games
> // aaaaaaa
> int a=0;
>
> Now, cl doesn't give any warning:
> D:\lcc\mc71\test>cl -W4 -c tt.c
> Microsoft (R) C/C++ Optimizing Compiler Version 14.00.50727.762 for x6
> Copyright (C) Microsoft Corporation. All rights reserved.
>
> tt.c
>
> D:\lcc\mc71\test>
>
> WORD GAMES as always.
>


Well, what do you expect if you do not tell CL to disable language
extensions? Add the /Za switch and also the /Wall switch and try again.

  Réponse avec citation
Vieux 27/04/2008, 12h38   #12
Keith Thompson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: // comments

jacob navia <jacob@nospam.com> writes:
> Flash Gordon wrote:
>> jacob navia wrote, On 27/04/08 08:59:
>>> Richard Heathfield wrote:
>>>> When invoked in conforming mode, Microsoft C (or at least my copy
>>>> of it) issues the necessary diagnostic message if you use // in an
>>>> erroneous syntactical context.
>>>
>>> D:\lcc\mc71\test>type tt.c
>>> // aaaaa
>>>
>>> D:\lcc\mc71\test>cl -W4 tt.c
>>> Microsoft (R) C/C++ Optimizing Compiler Version 14.00.50727.762 for x64
>>> Copyright (C) Microsoft Corporation. All rights reserved.
>>>
>>> tt.c
>>> tt.c(2) : warning C4206: nonstandard extension used : translation
>>> unit is empty
>>>
>>> Of course your version dates from 1991... Always the same word games,
>>> half truths, etc. Pure regulars BS.

>>
>> Not at all. You have just demonstrated that what Richard said is
>> true for the version you have as well. The compiler emitted a
>> diagnostic. There is no requirement for it to produce an error or
>> abort the translation. I have already posted saying that all you
>> have to do is detect it and issue a warning, as has Keith.

>
> word games, word games
> // aaaaaaa
> int a=0;
>
> Now, cl doesn't give any warning:
> D:\lcc\mc71\test>cl -W4 -c tt.c
> Microsoft (R) C/C++ Optimizing Compiler Version 14.00.50727.762 for x6
> Copyright (C) Microsoft Corporation. All rights reserved.
>
> tt.c
>
> D:\lcc\mc71\test>
>
> WORD GAMES as always.


I don't think the phrase "word games" means what you think it means.

You have demonstrated that Microsoft's C compiler, invoked with the
options you specified, is not a conforming C89/C90 compiler. If it
were, it would have issued a diagnostic for the "//".

I don't know whether "cl -W4 -c tt.c" invokes it in what is intended
to be C90 conforming mode. If not, you haven't demonstrated anything
of any significance.

*At most*, you've simply demonstrated that, *if* lcc-win's "-ansi89"
option is intended to invoke it in C89 conforming mode, then it
exhibits a bug (a failure to conform to the C89 standard) that
Microsoft's compiler also exhibits.

None of this matters much to me personally. Since it appears to
matter a great deal to you, perhaps you can answer these questions and
clear this up:

1. Is lcc-win's "-ansi89" option intended to invoke the compiler in a
mode that conforms to the ANSI C89 standard?

2. In that mode, does it issue a diagnostic for a "//" comment?

3. If it doesn't, do you acknowledge that that is a conformance
failure?

If this is a bug, I'm not saying it's terrifying, and I'm not pushing
to you fix it. I'm only asking you to clear up this issue.

--
Keith Thompson (The_Other_Keith) <kst-u@mib.org>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
  Réponse avec citation
Vieux 27/04/2008, 13h02   #13
ymuntyan@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: // comments

On Apr 27, 4:26 am, Flash Gordon <s...@flash-gordon.me.uk> wrote:
> jacob navia wrote, On 27/04/08 08:59:
>
> > Richard Heathfield wrote:
> >> Keith Thompson said:

>
> >>> jacob navia <ja...@nospam.com> writes:

>
> >> <snip>

>
> >>>> Note that many compilers at the C89 level accept // comments,

>
> >> If they are invoked in conforming mode, they *must* diagnose syntax
> >> errors.

>
> > Maybe. If they do not, please use another compiler.

>
> If you state that -ansi89 does *not* mean conformance to C89 (or C90 or
> C95) then as has already been stated it is allowed to accept whatever
> you want. If I was one of your paying customers I would not be happy,
> but I'm not.


Perhaps that customer wanted warnings for stuff which
reduces portability, like variadic macros not understood
by MS compiler?
(Yes I do realize that where were, and hence are, C compilers
which do not understand // comments)

Yevgen
  Réponse avec citation
Vieux 27/04/2008, 13h07   #14
ymuntyan@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: // comments

On Apr 27, 6:02 am, ymunt...@gmail.com wrote:
> On Apr 27, 4:26 am, Flash Gordon <s...@flash-gordon.me.uk> wrote:
>
>
>
> > jacob navia wrote, On 27/04/08 08:59:

>
> > > Richard Heathfield wrote:
> > >> Keith Thompson said:

>
> > >>> jacob navia <ja...@nospam.com> writes:

>
> > >> <snip>

>
> > >>>> Note that many compilers at the C89 level accept // comments,

>
> > >> If they are invoked in conforming mode, they *must* diagnose syntax
> > >> errors.

>
> > > Maybe. If they do not, please use another compiler.

>
> > If you state that -ansi89 does *not* mean conformance to C89 (or C90 or
> > C95) then as has already been stated it is allowed to accept whatever
> > you want. If I was one of your paying customers I would not be happy,
> > but I'm not.

>
> Perhaps that customer wanted warnings for stuff which
> reduces portability, like variadic macros not understood
> by MS compiler?
> (Yes I do realize that where were, and hence are, C compilers
> which do not understand // comments)


Actually I was wrong, I have no idea if there was a C
compiler which didn't understand // comments. By the time
when a compiler got to C90 conformance (N years after 1990),
// comments were probably already there. What conforming C90
compiler doesn't understand // comments? Just curious.

Yevgen
  Réponse avec citation
Vieux 27/04/2008, 13h23   #15
Flash Gordon
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: // comments

jacob navia wrote, On 27/04/08 11:05:
> Flash Gordon wrote:
>> jacob navia wrote, On 27/04/08 08:59:
>>> Richard Heathfield wrote:
>>>> When invoked in conforming mode, Microsoft C (or at least my copy of
>>>> it) issues the necessary diagnostic message if you use // in an
>>>> erroneous syntactical context.
>>>
>>> D:\lcc\mc71\test>type tt.c
>>> // aaaaa
>>>
>>> D:\lcc\mc71\test>cl -W4 tt.c
>>> Microsoft (R) C/C++ Optimizing Compiler Version 14.00.50727.762 for x64
>>> Copyright (C) Microsoft Corporation. All rights reserved.
>>>
>>> tt.c
>>> tt.c(2) : warning C4206: nonstandard extension used : translation
>>> unit is empty
>>>
>>> Of course your version dates from 1991... Always the same word games,
>>> half truths, etc. Pure regulars BS.

>>
>> Not at all. You have just demonstrated that what Richard said is true
>> for the version you have as well. The compiler emitted a diagnostic.
>> There is no requirement for it to produce an error or abort the
>> translation. I have already posted saying that all you have to do is
>> detect it and issue a warning, as has Keith.

>
> word games, word games


No, statements of fact.

> // aaaaaaa
> int a=0;
>
> Now, cl doesn't give any warning:
> D:\lcc\mc71\test>cl -W4 -c tt.c
> Microsoft (R) C/C++ Optimizing Compiler Version 14.00.50727.762 for x6
> Copyright (C) Microsoft Corporation. All rights reserved.
>
> tt.c
>
> D:\lcc\mc71\test>
>
> WORD GAMES as always.


You are the one playing word games. You know very well that if MS VC++
is invoked in conforming more it *does* produce a diagnostic for //
style comments. That is does not when *not* in conforming mode is *not*
an excuse for your compiler to fail to produce required diagnostics in a
claimed C89 conforming mode.

Also MS VCC++ not producing a diagnostic in non-conforming mode does not
contradict what Richard says above.

Either accept that on your compiler -ansi89 does not make it conforming
(which would seem strange to me but it's your choice) or accept that you
have a bug. Do not try and use the non-conforming mode of other
compilers as an excuse if you are attempting to provide a conforming mode.
--
Flash Gordon
  Réponse avec citation
Vieux 27/04/2008, 13h48   #16
Ben Bacarisse
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: // comments

ymuntyan@gmail.com writes:

> On Apr 27, 4:26 am, Flash Gordon <s...@flash-gordon.me.uk> wrote:
>> jacob navia wrote, On 27/04/08 08:59:

<snip>
>> If you state that -ansi89 does *not* mean conformance to C89 (or C90 or
>> C95) then as has already been stated it is allowed to accept whatever
>> you want. If I was one of your paying customers I would not be happy,
>> but I'm not.

>
> Perhaps that customer wanted warnings for stuff which
> reduces portability, like variadic macros not understood
> by MS compiler?


Then they would be disappointed. I am not sure to what extent it is
either wise or topical to go into details but -ansi89 does not
diagnose variadic macros (as it should). Fortunately, the
implementation of them seems to be broken so the user would likely
find out if they tried to use them. It seems that -ansi89 also
permits long long int, treats restrict as a keyword, does not diagnose
the use of compound literals, permits [static N] in function
parameters... I stopped looking after a while[1].

Its use for checking portability would be rather limited, I think.

[1] To be balanced, it does diagnose some non ANSI C constructs.

--
Ben.
  Réponse avec citation
Vieux 27/04/2008, 14h26   #17
santosh
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: // comments

Ben Bacarisse wrote:

> ymuntyan@gmail.com writes:
>
>> On Apr 27, 4:26 am, Flash Gordon <s...@flash-gordon.me.uk> wrote:
>>> jacob navia wrote, On 27/04/08 08:59:

> <snip>
>>> If you state that -ansi89 does *not* mean conformance to C89 (or C90
>>> or C95) then as has already been stated it is allowed to accept
>>> whatever you want. If I was one of your paying customers I would not
>>> be happy, but I'm not.

>>
>> Perhaps that customer wanted warnings for stuff which
>> reduces portability, like variadic macros not understood
>> by MS compiler?

>
> Then they would be disappointed. I am not sure to what extent it is
> either wise or topical to go into details but -ansi89 does not
> diagnose variadic macros (as it should). Fortunately, the
> implementation of them seems to be broken so the user would likely
> find out if they tried to use them. It seems that -ansi89 also
> permits long long int, treats restrict as a keyword, does not diagnose
> the use of compound literals, permits [static N] in function
> parameters... I stopped looking after a while[1].
>
> Its use for checking portability would be rather limited, I think.
>
> [1] To be balanced, it does diagnose some non ANSI C constructs.


Maybe jacob implemented -ansi89 switch as a synonym for -ansi?

  Réponse avec citation
Vieux 27/04/2008, 14h36   #18
Richard Heathfield
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: // comments

jacob navia said:

> Richard Heathfield wrote:


<snip>

>> When invoked in conforming mode, Microsoft C (or at least my copy of it)
>> issues the necessary diagnostic message if you use // in an erroneous
>> syntactical context.
>>

>
>
> D:\lcc\mc71\test>type tt.c
> // aaaaa
>
> D:\lcc\mc71\test>cl -W4 tt.c
> Microsoft (R) C/C++ Optimizing Compiler Version 14.00.50727.762 for x64
> Copyright (C) Microsoft Corporation. All rights reserved.
>
> tt.c
> tt.c(2) : warning C4206: nonstandard extension used : translation unit
> is empty
>
> Of course your version dates from 1991... Always the same word games,
> half truths, etc. Pure regulars BS.


Firstly, even a conforming implementation is only obliged to issue *one*
diagnostic message for any translation unit that violates any syntactic
rules or constraints, and the form of that message is up to the
implementation. If a translation unit contains two or more such
violations, an implementation only need diagnose one of them. In that
respect, your log does not prove that MS C violates conformance by not
producing the diagnostic message you'd like to see - by producing one at
all, it conforms.

Secondly, you have not even invoked it in conforming mode!

It seems that you are determined to fail to understand the point being made
here. Now try adding the -Za switch to your invocation, to instruct MS C
to disable language extensions. Then give it a translation unit that
contains no other violations of syntactic rules or constraints - for
example:

#include <stdio.h>

int main(void)
{
puts("Hello, world!"); // this is a syntax error
return 0;
}

If you call this translation unit tt.c and invoke Microsoft C in conforming
mode as follows:

cl -W4 -Za tt.c

what diagnostic messages do you get?

--
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
  Réponse avec citation
Vieux 27/04/2008, 14h36   #19
Ben Bacarisse
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: // comments

santosh <santosh.k83@gmail.com> writes:

> Ben Bacarisse wrote:
>> ymuntyan@gmail.com writes:

<snip>
>>> Perhaps that customer wanted warnings for stuff which
>>> reduces portability, like variadic macros not understood
>>> by MS compiler?

>>
>> Then they would be disappointed.

<snip>
>> [1] To be balanced, it does diagnose some non ANSI C constructs.

>
> Maybe jacob implemented -ansi89 switch as a synonym for -ansi?


Sorry, I don't follow.

--
Ben.
  Réponse avec citation
Vieux 27/04/2008, 14h42   #20
Harald van Dijk
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: // comments

On Sun, 27 Apr 2008 13:36:20 +0100, Ben Bacarisse wrote:
> santosh <santosh.k83@gmail.com> writes:
>> Maybe jacob implemented -ansi89 switch as a synonym for -ansi?

>
> Sorry, I don't follow.


With GCC, -ansi means that valid C90 programs will be accepted, but
invalid C90 programs, complete with syntax errors and/or constraint
violations, will not necessarily be rejected. It's possible that jacob
navia made -ansi89 behave the same way in lcc-win32.
  Réponse avec citation
Vieux 27/04/2008, 14h48   #21
Bartc
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: // comments


"Ben Bacarisse" <ben.usenet@bsb.me.uk> wrote in message
news:87ej8s5ep6.fsf@bsb.me.uk...
> jacob navia <jacob@nospam.com> writes:
>
>> Recently we had poor Mr "teapot" that was horrified at the heresy
>> of lcc-win of accepting // comments.

>
> Can you clear up the question of what the -ansi89 flag is intended to
> do? Your compiler is allowed to accept any extensions it likes and to
> reject and conforming C90 programs it wishes to *unless* you claim that
> lc -ansi89 is intended to be a conforming C90 implementation. What is
> the purpose of -ansi89?
>
>> C is a nice language, and you can do anything with it, inclusive a
>> program that transforms // comments into well behaved /* ... */
>> ones...

>
> How do you do that with:
>
> int main(void) { return 1//* divide? */2; }
>
> Is this a valid C90 program or an incorrect C90 one that has a //
> comment int it?


I think it's more of a problem of the design of the // comment convention,
in that this ambiguity can occur.

I would guess that in the case of Jacob's code, it's assuming input is of a
file where // can legally occur. It will translate that into a form that
will give a compilation error (in any mode). Then the user can trace back
and see immediately where the problem is.

That's no different from feeding this code to practically any compiler that
by default accepts // comments; it will report an error and the user can
either invoke conforming mode or (more sensibly so that it gives no further
problems) turn // into / /).

For Jacob's code to work sensibly, it would need a switch to tell it the
input has pure C90-conforming comments, but if someone knew that, there
would be no need to run the program!

--
Bartc


  Réponse avec citation
Vieux 27/04/2008, 14h55   #22
Ben Bacarisse
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: // comments

Harald van Dijk <truedfx@gmail.com> writes:

> On Sun, 27 Apr 2008 13:36:20 +0100, Ben Bacarisse wrote:
>> santosh <santosh.k83@gmail.com> writes:
>>> Maybe jacob implemented -ansi89 switch as a synonym for -ansi?

>>
>> Sorry, I don't follow.

>
> With GCC, -ansi means that valid C90 programs will be accepted, but
> invalid C90 programs, complete with syntax errors and/or constraint
> violations, will not necessarily be rejected. It's possible that jacob
> navia made -ansi89 behave the same way in lcc-win32.


I considered that meaning, but since santosh was replying to a message
that stated that -ansi89 treats restrict as a keyword, that did not
seem like a reasonable interpretation.

--
Ben.
  Réponse avec citation
Vieux 27/04/2008, 15h15   #23
Flash Gordon
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: // comments

Harald van Dijk wrote, On 27/04/08 13:42:
> On Sun, 27 Apr 2008 13:36:20 +0100, Ben Bacarisse wrote:
>> santosh <santosh.k83@gmail.com> writes:
>>> Maybe jacob implemented -ansi89 switch as a synonym for -ansi?

>> Sorry, I don't follow.

>
> With GCC, -ansi means that valid C90 programs will be accepted, but
> invalid C90 programs, complete with syntax errors and/or constraint
> violations, will not necessarily be rejected. It's possible that jacob
> navia made -ansi89 behave the same way in lcc-win32.


I believe that on lcc-win32 -ansic selects C99 conformance (modulo bugs
and bits not implemented). So if -ansi99 was a synonym for -ansic it
would also select C99 conformance and thus allow // comments, treat
restrict as a keyword etc.
--
Flash Gordon
  Réponse avec citation
Vieux 27/04/2008, 15h22   #24
santosh
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: // comments

Ben Bacarisse wrote:

> Harald van D?k <truedfx@gmail.com> writes:
>
>> On Sun, 27 Apr 2008 13:36:20 +0100, Ben Bacarisse wrote:
>>> santosh <santosh.k83@gmail.com> writes:
>>>> Maybe jacob implemented -ansi89 switch as a synonym for -ansi?
>>>
>>> Sorry, I don't follow.

>>
>> With GCC, -ansi means that valid C90 programs will be accepted, but
>> invalid C90 programs, complete with syntax errors and/or constraint
>> violations, will not necessarily be rejected. It's possible that
>> jacob navia made -ansi89 behave the same way in lcc-win32.

>
> I considered that meaning, but since santosh was replying to a message
> that stated that -ansi89 treats restrict as a keyword, that did not
> seem like a reasonable interpretation.


Yes. The lcc-win manual that I have indicates that the -ansi switch
makes the compiler conform to C99. Your post up-thread which seemed to
indicate that lcc-win