Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > // at beginning of line

Reply
Thread Tools

// at beginning of line

 
 
Federico
Guest
Posts: n/a
 
      06-01-2011
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.
 
Reply With Quote
 
 
 
 
Ben Pfaff
Guest
Posts: n/a
 
      06-01-2011
Federico <(E-Mail Removed)> 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://benpfaff.org
 
Reply With Quote
 
 
 
 
Angel
Guest
Posts: n/a
 
      06-01-2011
On 2011-06-01, Federico <(E-Mail Removed)> 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
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      06-01-2011
Federico <(E-Mail Removed)> 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) http://www.velocityreviews.com/forums/(E-Mail Removed) <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"
 
Reply With Quote
 
Federico
Guest
Posts: n/a
 
      06-01-2011
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 <(E-Mail Removed)> 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.


 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      06-01-2011
Federico <(E-Mail Removed)> writes:
> Angel writes:
>> On 2011-06-01, Federico <(E-Mail Removed)> 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) (E-Mail Removed) <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"
 
Reply With Quote
 
Angel
Guest
Posts: n/a
 
      06-01-2011
On 2011-06-01, Federico <(E-Mail Removed)> wrote:
[ top posting fixed ]
> Angel writes:
>> On 2011-06-01, Federico <(E-Mail Removed)> 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
 
Reply With Quote
 
Shao Miller
Guest
Posts: n/a
 
      06-02-2011
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
 
Reply With Quote
 
Malcolm McLean
Guest
Posts: n/a
 
      06-02-2011
On Jun 1, 10:56*pm, Keith Thompson <(E-Mail Removed)> 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.


 
Reply With Quote
 
Jorgen Grahn
Guest
Posts: n/a
 
      06-02-2011
On Thu, 2011-06-02, Malcolm McLean wrote:
> On Jun 1, 10:56*pm, Keith Thompson <(E-Mail Removed)> 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 .
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
index of string from beginning of line vs beginning of file Jesse B. Ruby 9 03-27-2010 04:04 PM
In The Beginning ... Was The Command Line Lawrence D'Oliveiro NZ Computing 0 10-13-2006 08:06 AM
Ruby-esque approaches to adding a line at the beginning of a file. Randy Kramer Ruby 3 03-26-2006 10:05 PM
Can I stop VWD inserting spaces at the beginning of the line? Alan Silver ASP .Net 2 11-14-2005 08:01 PM
Parse an xml file with line breaks in the beginning Raj Mudaliar Perl 0 07-14-2003 06:00 PM



Advertisments