Content deleted Content added
Stevebroshar (talk | contribs) →Common attributes: add example |
Velocifyer (talk | contribs) |
||
(16 intermediate revisions by 10 users not shown) | |||
Line 55:
*/
bool foo() {
return true; /* inline
}
Line 126:
Comments can store [[metadata]] about the code. Common metadata includes the name of the original author and subsequent maintainers, dates when first written and modified, link to development and user documentation, and legal information such as [[copyright]] and [[software license]].
Some [[programming tools]] write metadata into the code as comments.<ref>See e.g., {{cite book |last=Wynne-Powell |first=Rod |year=2008 |title=Mac OS X for Photographers: Optimized Image Workflow for the Mac User |page=243 |publisher=Focal Press |___location=Oxford |isbn=978-0-240-52027-8 |url=https://archive.org/details/macosxforphotogr0000wynn}}</ref> For example, a [[version control]] tool might write metadata such as author, date and version number into each file when it's
=== Integrate with development tools ===
Line 145:
| publisher=Cambridge University Press
| isbn=978-1-397-80521-8
}}</ref> Examples include [[Javadoc]],
=== Visualization ===
Line 193:
=== Extend language syntax ===
Occasionally, code that is formatted as a comment is overloaded to convey additional information to the translator, such as
Other examples include interpreter [[Directive (programming)|directives]]:
Line 292:
<syntaxhighlight lang="c">
/***************************
* *
* This is the comment body. *
* *
</syntaxhighlight>
Line 333:
==Tags==
Programmers often use one of select words {{endash}} also
Commonly used tags include:
Line 354:
===Curly brace languages===
Many of the [[curly brace language]]s such as C, C++ and their many derivatives delimit a line comment with {{code|//}} and a block comment with {{code|/*}} and {{code|*/}}. Originally, C lacked the line comment, but it was added in [[C99]]. Notable languages include: C, C++, [[C# (programming language)|C#]], [[D (programming language)|D]], [[Java (programming language)|Java]], [[
<syntaxhighlight lang="c">
Line 574:
====APL====
[[APL (programming language)|APL]] uses <code>⍝</code> ("lamp") for a line comment. For example:
<syntaxhighlight lang="apl">
Line 590:
<syntaxhighlight lang="AppleScript">
# line comment (in later versions)
(*
This program displays a greeting.
Line 644 ⟶ 645:
====Fortran====
The following fixed-form [[Fortran
<syntaxhighlight lang="fortranfixed">
Line 659 ⟶ 660:
<syntaxhighlight lang="Fortran">
! A comment
program comment_test
print '(A)', 'Hello world' ! also a comment
end program
</syntaxhighlight>
Free-form Fortran, also introduced with Fortran 90, only supports this latter style of comment.
Although not a part of the Fortran Standard, many Fortran compilers offer an optional C-like [[preprocessor]] pass. This can be used to provide block comments:
<syntaxhighlight lang="Fortran">
#if 0
This is a block comment spanning
multiple lines.
#endif
program comment_test
print '(A)', 'Hello world' ! also a comment
Line 707 ⟶ 722:
====OCaml====
[[OCaml]] supports nestable comments. For
<syntaxhighlight lang="ocaml">
codeLine(* comment level 1(*comment level 2*)*)
Line 714 ⟶ 729:
====Pascal, Delphi====
▲As an alternative, for computers that do not support these characters, '(* ... *)' are allowed.<ref>{{cite book|author=Kathleen Jensen, Niklaus Wirth|year=1985|title=Pascal User Manual and Report|publisher=Springer-Verlag|isbn=0-387-96048-1}}</ref> In [[Niklaus Wirth]]'s more modern family of languages (including [[Modula-2]] and [[Oberon (programming language)|Oberon]]), comments are delimited by '(* ... *)'.<ref>{{cite book|author=Niklaus Wirth|year=1983|title=Programming in Modula-2|publisher=Springer-Verlag|isbn=0-387-15078-1}}</ref><ref>*{{cite book|author=Martin Reiser, Niklaus Wirth|year=1992|title=Programming in Oberon|publisher=Addison-Wesley|isbn=0-201-56543-9}}</ref> Comments can be nested. // can be included in a {} and {} can be included in a (**). For example:
<syntaxhighlight lang="pascal">
|