[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c

// at beginning of line

Federico

6/1/2011 7:45:00 PM

Hello. I'd like to understand the following piece of source:

..........

fscanf ( Infile, "%3s %6s", string1, string2);
//fscanf(Infile,"%5s %5s",string3,string4);

^^--------- I don't know the meaning of this double slash.

Thank you in advance.
Federico.
35 Answers

Ben Pfaff

6/1/2011 7:48:00 PM

0

Federico <no.adress@nospam.com> writes:

> //fscanf(Infile,"%5s %5s",string3,string4);
>
> ^^--------- I don't know the meaning of this double slash.

In C99, it introduces a comment that runs until the end of the
line.
--
Ben Pfaff
http://be...

Angel

6/1/2011 7:55:00 PM

0

On 2011-06-01, Federico <no.adress@nospam.com> wrote:
> Hello. I'd like to understand the following piece of source:
>
> .........
>
> fscanf ( Infile, "%3s %6s", string1, string2);
> //fscanf(Infile,"%5s %5s",string3,string4);
>
> ^^--------- I don't know the meaning of this double slash.

That line is commented out. Everything after // up till the end of the
line is a comment.

This construction comes from C++, but several compilers (like gcc) made
it available as an extension to C. In C99, this was made official.


--
"C provides a programmer with more than enough rope to hang himself.
C++ provides a firing squad, blindfold and last cigarette."
- seen in comp.lang.c

Keith Thompson

6/1/2011 7:57:00 PM

0

Federico <no.adress@nospam.com> writes:
> Hello. I'd like to understand the following piece of source:
>
> .........
>
> fscanf ( Infile, "%3s %6s", string1, string2);
> //fscanf(Infile,"%5s %5s",string3,string4);
>
> ^^--------- I don't know the meaning of this double slash.

It introduces a comment, which extends from the "//" to the end of
the line.

It's one of two forms of comments supported by C. The other is
introduced by "/*" and terminated by "*/". (There's more to it
than that, but I won't get into the gory details.)

Note that the C90 standard didn't support "//" comments, only
"/* ... */" comments. C99 introduced "//" comments (borrowed
from C++, and ultimately from BCPL). So your C compiler might not
recognize "//" comments, or might require some option to cause it
to recognize them. (I think most modern C compilers do recognize
"//" comments by default.)

--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.ne...
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

Federico

6/1/2011 8:46:00 PM

0

Thank u. My compiler is for C not C++ and he gives an error of
"unexpected token - missing semicolon?".

Would it be acceptable to replace with a normal comment /* ... */ ? Or
even delete the line all in all ?

Federico.


Angel writes:
> On 2011-06-01, Federico <no.adress@nospam.com> wrote:
>> Hello. I'd like to understand the following piece of source:
>>
>> .........
>>
>> fscanf ( Infile, "%3s %6s", string1, string2); //fscanf(Infile,"%5s
>> %5s",string3,string4);
>>
>> ^^--------- I don't know the meaning of this double slash.
>
> That line is commented out. Everything after // up till the end of the
> line is a comment.
>
> This construction comes from C++, but several compilers (like gcc) made
> it available as an extension to C. In C99, this was made official.

Keith Thompson

6/1/2011 8:55:00 PM

0

Federico <no.adress@nospam.com> writes:
> Angel writes:
>> On 2011-06-01, Federico <no.adress@nospam.com> wrote:
>>> Hello. I'd like to understand the following piece of source:
>>>
>>> .........
>>>
>>> fscanf ( Infile, "%3s %6s", string1, string2); //fscanf(Infile,"%5s
>>> %5s",string3,string4);
>>>
>>> ^^--------- I don't know the meaning of this double slash.
>>
>> That line is commented out. Everything after // up till the end of the
>> line is a comment.
>>
>> This construction comes from C++, but several compilers (like gcc) made
>> it available as an extension to C. In C99, this was made official.
>
> Thank u. My compiler is for C not C++ and he gives an error of
> "unexpected token - missing semicolon?".

It would have been *extremely* helpful if you had mentioned that in the
first place.

> Would it be acceptable to replace with a normal comment /* ... */ ? Or
> even delete the line all in all ?

Sure. Or find out how to get your C compiler (which one are you using?)
to recognize // comments.

--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.ne...
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

Angel

6/1/2011 8:59:00 PM

0

On 2011-06-01, Federico <no.adress@nospam.com> wrote:
[ top posting fixed ]
> Angel writes:
>> On 2011-06-01, Federico <no.adress@nospam.com> wrote:
>>> Hello. I'd like to understand the following piece of source:
>>>
>>> .........
>>>
>>> fscanf ( Infile, "%3s %6s", string1, string2); //fscanf(Infile,"%5s
>>> %5s",string3,string4);
>>>
>>> ^^--------- I don't know the meaning of this double slash.
>>
>> That line is commented out. Everything after // up till the end of the
>> line is a comment.
>>
>> This construction comes from C++, but several compilers (like gcc) made
>> it available as an extension to C. In C99, this was made official.
>
> Thank u. My compiler is for C not C++ and he gives an error of
> "unexpected token - missing semicolon?".

You may have to tell your compiler to use the C99 standard. With GNU's
gcc, adding -std=c99 to the command line does that. I don't know for
other compilers, consult your documentation.

> Would it be acceptable to replace with a normal comment /* ... */ ? Or
> even delete the line all in all ?

Yes to both. As far as the compiler is concerned, comments are white
space and are ignored completely.


--
"C provides a programmer with more than enough rope to hang himself.
C++ provides a firing squad, blindfold and last cigarette."
- seen in comp.lang.c

Shao Miller

6/2/2011 4:05:00 AM

0

On 6/1/2011 2:44 PM, Federico wrote:
> Hello. I'd like to understand the following piece of source:
>
> .........
>
> fscanf ( Infile, "%3s %6s", string1, string2);
> //fscanf(Infile,"%5s %5s",string3,string4);
>
> ^^--------- I don't know the meaning of this double slash.

You might also enjoy:

fscanf(Infile, "%3s %6s", string1, string2);
#if 0
fscanf(Infile, "%5s %5s", string3, string4);
#endif

or even:

#define TEST_MODE 0
...
fscanf(Infile, "%3s %6s", string1, string2);
#if TEST_MODE
fscanf(Infile, "%5s %5s", string3, string4);
#endif

or maybe:

#define TEST_MODE 0
...
#if !TEST_MODE
fscanf(Infile, "%3s %6s", string1, string2);
#else
fscanf(Infile, "%5s %5s", string3, string4);
#endif

Malcolm McLean

6/2/2011 6:07:00 AM

0

On Jun 1, 10:56 pm, Keith Thompson <ks...@mib.org> wrote:
> (I think most modern C compilers do recognize
> "//" comments by default.)
>
My MPI (message passing interface) compiler didn't.
I had written everything in strict ANSI C, with the exception of slash
slash comments, because I thought that surely they were universally
accepted by now. They're also handy for allowing you to comment out
code with slash star comments. On MPI you can't run a debugger, so
it's important to be able to comment out code to try to track down
bugs.

However the cluster compiler wouldn't accept the code. Minor nuisance,
but in programming minor nuisances have a way of becoming major
nuisances.


Jorgen Grahn

6/2/2011 7:16:00 AM

0

On Thu, 2011-06-02, Malcolm McLean wrote:
> On Jun 1, 10:56 pm, Keith Thompson <ks...@mib.org> wrote:
>> (I think most modern C compilers do recognize
>> "//" comments by default.)
>>
> My MPI (message passing interface) compiler didn't.

[Googled it. It's related to some grid computing environment.]

> I had written everything in strict ANSI C, with the exception of slash
> slash comments, because I thought that surely they were universally
> accepted by now.

It's a somewhat unfortunate choice in general, because it prevents you
from using C89 tools on the code (such as gcc -std=c89). If you don't
have C99 tools available, you become reliant on sloppy tools which
accept C89 + // comments + an unknown other set of extensions (such as
gcc -std=gnu89).

> They're also handy for allowing you to comment out
> code with slash star comments. On MPI you can't run a debugger, so
> it's important to be able to comment out code to try to track down
> bugs.

I almost always use #if 0 for such things.

I rarely use // even in C++ code; it's IME rare to have to something
that needs documentation, yet not need more than a few words. I prefer
block comments of full sentences. // comments often appear as cryptic
footnotes, squeezed together to the right.

All IMHO of course.

> However the cluster compiler wouldn't accept the code. Minor nuisance,
> but in programming minor nuisances have a way of becoming major
> nuisances.

There are more desirable C99 features you're missing, like the ability
to declare variables where they are used rather than at the top of the
enclosing block. I really miss that when I have to use C89.

/Jorgen

--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .

Chris H

6/2/2011 7:40:00 AM

0

In message <slrniuee5c.gtj.grahn+nntp@frailea.sa.invalid>, Jorgen Grahn
<grahn+nntp@snipabacken.se> writes
>On Thu, 2011-06-02, Malcolm McLean wrote:
>It's a somewhat unfortunate choice in general, because it prevents you
>from using C89 tools on the code (such as gcc -std=c89). If you don't
>have C99 tools available, you become reliant on sloppy tools which
>accept C89 + // comments + an unknown other set of extensions (such as
>gcc -std=gnu89).


The tools that accept C90 + // are not sloppy. On the other hand GCC
is.

The // was added to C99 because the vast majority of C95 compilers had
it. The job of ISO standards is to standardise what the industry is
doing not go off on flights of fancy which is why virtually no one fully
implements C99 over a decade on.

In fact if C12 comes out on time C99 will be the standard that never
was.



--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/