주석
주석 (Comments) — 1.2
소스에 설명을 남기고 싶을 때 쓰는 **주석(comment)**은 컴파일러가 완전히 무시하는 코드 조각이에요. 주석은 오직 프로그래머를 위한 존재라서, 컴파일러 입장에서는 마치 존재하지 않는 것처럼 처리돼요.
본문
주석을 보여주는 간단한 예시예요. (* 와 *) 로 감싼 부분이 주석이 돼요.
(* My beautiful function returns an interesting result *)
Function Beautiful : Integer;
(* 와 *) 를 주석 구분자로 쓰는 방식은 파스칼 언어 초창기부터 이어져 왔어요. 지금은 대부분 { 와 } 를 구분자로 쓰는데, 다음 예시처럼요.
{ My beautiful function returns an interesting result }
Function Beautiful : Integer;
주석은 여러 줄에 걸쳐 쓸 수도 있어요.
{
My beautiful function returns an interesting result,
but only if the argument A is less than B.
}
Function Beautiful (A,B : Integer): Integer;
// 구분자로 한 줄 주석을 만들 수도 있어요.
// My beautiful function returns an interesting result
Function Beautiful : Integer;
이 주석은 // 문자부터 줄 끝까지 이어져요. 이 방식은 Borland가 Delphi 파스칼 컴파일러에서 처음 도입했어요.
중첩 주석
Free Pascal은 **중첩 주석(nested comments)**을 지원해요. 다음 구성들은 유효한 주석이에요.
(* This is an old style comment *)
{ This is a Turbo Pascal comment }
// This is a Delphi comment. All is ignored till the end of the line.
다음은 중첩 주석이 유효한 경우들이에요.
{ Comment 1 (* comment 2 *) }
(* Comment 1 { comment 2 } *)
{ comment 1 // Comment 2 }
(* comment 1 // Comment 2 *)
// comment 1 (* comment 2 *)
// comment 1 { comment 2 }
주의할 점
마지막 두 주석(// comment 1 (* comment 2 *) 와 // comment 1 { comment 2 })은 반드시 한 줄에 있어야 해요. 다음 두 가지는 오류를 일으켜요.
// Valid comment { No longer valid comment !!
}
그리고
// Valid comment (* No longer valid comment !!
*)
이런 구성을 만나면 컴파일러는 -Mtp 스위치와 무관하게 "invalid character"(잘못된 문자) 오류로 응답해요.
Remark —
TP와Delphi모드에서는 그 컴파일러들의 기존 코드와의 최대 호환성을 위해 중첩 주석이 허용되지 않아요.