본문 바로가기

망각/Obj/C/++/#

L-Value and R-Value Expressions - MSDN

출처: MSDN

C Language Reference

L-Value and R-Value Expressions

메모리 위치를 참조하는 표현을 "l-value" 표현이라 불리운다. l-value 은 저장 영역의 "locator" 값이나, 또는 암시적으로 등호 부호(=)의 왼쪽에 나타날수있다는 있는 "left" 값을 나타낸다. L-value들은 종종 식별자(identifier)들이다.

표현이 변경가능한 위치를 참조하는 것을 "modifiable l-values" 라고 부른다. 변경가능한 l-value은 배열 타입, 불완전한 타입, 또는 const 속석의 타입을 가질 수 없다. 구조체와 공용체는 변경가능한 l-valus들이다, 그것들은 const속성의 멤버들을 가지지 않는다. 식별자의 이름은 저장 위치(stroage location)를 나타내는 반면, 변수의 값(value)은 그 위치에 저장된다.

식별자가 메모리 위치를 참조하고, 그것의 타입이 정수, 구조체, 공용체, 포인터라면 변경가능한 l-value 이다.
예를 들어, ptr 이 저장 영역에 대한 포인터라면, *ptr은 ptr 이 가르키는 저장 영역을 나타내는 변경가능한 l-value이다.

다음의 C 표현들은 l-value 표현이 될수 있다:

  • An identifier of integral, floating, pointer, structure, or union type
  • A subscript ([ ]) expression that does not evaluate to an array
  • A member-selection expression (–> or .)
  • A unary-indirection (*) expression that does not refer to an array
  • An l-value expression in parentheses
  • A const object (a nonmodifiable l-value)

"r-value" 용어는 때때로 표현의 값을 설명하기 위하거나, l-value에서 그것을 분간하기 위해 사용된다.
모든 l-value은 r-value이지만, 모든 r-value가 l-value는 아니다.

Microsoft Specific —>

Microsoft C includes an extension to the ANSI C standard that allows casts of l-values to be used as l-values, as long as the size of the object is not lengthened through the cast. (See Type-Cast Conversions for more information.) The following example illustrates this feature:

char *p ;
short i;
long l;


(long *) p = &l ; /* Legal cast */
(long) i = l ; /* Illegal cast */

The default for Microsoft C is that the Microsoft extensions are enabled. Use the /Za compiler option to disable these extensions.

END Microsoft Specific

© Microsoft Corporation. All rights reserved.

'망각 > Obj/C/++/#' 카테고리의 다른 글

포인터 변수에 const 사용  (0) 2007.04.13
L-Values and R-Values - MSDN  (0) 2006.05.26
VC++ 에서 콘솔창 띄우기  (0) 2006.05.25
strncmp로 문자열 비교중 삽질  (0) 2006.05.05