For faster navigation, this Iframe is preloading the Wikiwand page for 표명.

표명

컴퓨터 프로그래밍에서 표명(表明), 가정 설정문(假定設定文) 또는 어서션(영어: assertion)은 프로그램 안에 추가하는 참·거짓을 미리 가정하는 문이다. 개발자는 해당 문이 그 문의 장소에서 언제나 참이라고 간주한다. 런타임 중에 표명이 거짓으로 평가되면 표명 실패(assertion failure)를 초래하며 이 상황에서는 일반적으로 실행이 중단된다.

세부 설명

[편집]

다음의 코드에는 두 개의 표명 x > 0, x > 1이 있으며 실행 중에 이들은 주어진 위치에서 실제로 참으로 간주된다:

x = 1;
assert (x > 0);
x++;
assert (x > 1);

프로그래머들이 표명을 사용하면 프로그램들을 지정하고 프로그램 유효성을 추정할 수 있다. 이를테면 전제 조건(precondition), 즉 특정 코드 부분의 시작점에 위치한 표명은 코드가 실행될 것으로 예측하는 상태의 집합을 결정한다. 후행 조건(postcondition), 즉, 마지막에 위치한 표명은 실행 종료 시점에서 예측되는 상태를 기술한다. (예: x > 0 { x++ } x > 1)

상기의 예는 토니 호어가 그의 1969년 논문에 표명을 포함하기 위해 기술하고 있다.[1] 해당 기술은 현존하는 주류 프로그래밍 언어에서는 이용할 수 없다. 그러나 프로그래머들은 프로그래밍 언어의 주석 기능을 이용하여 비검사형 표명(unchecked assertion)을 포함할 수 있다. 이를테면 C에서는 다음과 같다:

x = 5;
x = x + 1;
// {x > 1}

주석에 들어간 중괄호를 통해 다른 용도의 주석과 구별할 수 있다.

라이브러리를 통해 표명 기능을 이용할 수 있다. 이를테면 C99을 지원하는 glibc를 이용하는 C에서는 다음과 같다:

#include <assert.h>
x = 5;
x = x + 1;
assert(x > 1);

현대의 일부 프로그래밍 언어는 런타임 중에서나 이따금 정적인 상태에서 검사되는 을 가리키는 검사형 표명(checked assertion)을 포함하기도 한다. 런타임 중에 표명이 거짓으로 평가되면 표명 실패(assertion failure)를 초래하여 실행이 중단되는 것이 일반적이다. 이를 통해 논리적 불일치가 감지된 위치에 집중할 수 있고 개발자는 의외의 결과가 나타나는 경우 보다 이 방법을 더 선호할 수 있다.

표명을 이용하면 프로그래머가 프로그램에 대한 설계, 개발, 추론을 도울 수 있다.

같이 보기

[편집]

각주

[편집]
  1. C.A.R. Hoare, An axiomatic basis for computer programming, Communications of the ACM, 1969.

외부 링크

[편집]
{{bottomLinkPreText}} {{bottomLinkText}}
표명
Listen to this article

This browser is not supported by Wikiwand :(
Wikiwand requires a browser with modern capabilities in order to provide you with the best reading experience.
Please download and use one of the following browsers:

This article was just edited, click to reload
This article has been deleted on Wikipedia (Why?)

Back to homepage

Please click Add in the dialog above
Please click Allow in the top-left corner,
then click Install Now in the dialog
Please click Open in the download dialog,
then click Install
Please click the "Downloads" icon in the Safari toolbar, open the first download in the list,
then click Install
{{::$root.activation.text}}

Install Wikiwand

Install on Chrome Install on Firefox
Don't forget to rate us

Tell your friends about Wikiwand!

Gmail Facebook Twitter Link

Enjoying Wikiwand?

Tell your friends and spread the love:
Share on Gmail Share on Facebook Share on Twitter Share on Buffer

Our magic isn't perfect

You can help our automatic cover photo selection by reporting an unsuitable photo.

This photo is visually disturbing This photo is not a good choice

Thank you for helping!


Your input will affect cover photo selection, along with input from other users.

X

Get ready for Wikiwand 2.0 🎉! the new version arrives on September 1st! Don't want to wait?