C¿Í C++°ü·Ã

HomePage Backward Forward Post Reply List
Delete Modify
  Á¦¸ñ   volatile 1998/07/29 (14:30)
À̸§ swindler
¹øÈ£ 13
Á¶È¸ 704
º»¹® volatileÀº ÄÄÆÄÀÏ ÃÖÀûÈ­ °úÁ¤¿¡¼­µµ ·¹Áö½ºÅÍ¿¡ º¯¼ö°¡
ÀúÀåµÇÁö ¾Êµµ·Ï ÇÑ´Ù.
¸¸¾à¿¡ ¸Þ¸ð¸®°¡ ¾Æ´Ñ ·¹Áö½ºÅÍ¿¡ º¯¼ö°¡ ·ÎµåµÈ´Ù¸é, ¸ÖƼ
½º·¹µù°ú °°Àº °æ¿ì¿¡ ¹®Á¦°¡ »ý±ä´Ù.
assemblerÄڵ带 ¶â¾îº¸¸é ¾Ë ¼ö ÀÖÁö¸¸,
º¯¼ö°¡ ·¹Áö½ºÅÍ¿¡ ·ÎµåµÇ°í ·¹Áö½ºÅÍ°¡ Áõ°¡µÈ ´ÙÀ½¿¡´Â
·¹Áö½ºÅÍÀÇ °ªÀÌ ´Ù½Ã º¯¼ö¿¡ ÀúÀåµÈ´Ù.
ÇÑ ½º·¹µå¿¡¼­ º¯¼ö¸íÀ» ·¹Áö½ºÅÍ¿¡ ·Îµå½ÃŲ´Ù¸é,
´Ù¸¥ ½º·¹µå°¡ ¸Þ¸ð¸®¿¡¼­ °ªÀ» º¯°æÇÑ´Ù ÇÏ´õ¶óµµ ¿ø·¡
½º·¹µå¿¡´Â ¾Æ¹«·± ¿µÇâÀ» ¹ÌÄ¡Áö ¸øÇÏ°Ô µÈ´Ù.
volatileÀ» ¼±¾ðÇϸé, º¯¼ö°¡ ·¹Áö½ºÅÍ¿¡ ÀúÀåµÇÁö ¾Êµµ·Ï
ÇÒ ¼ö ÀÖ´Ù.

volatileÇüÀº ÇöÀç ¼öÇàÁßÀÎ ÇÁ·Î±×·¥ÀÇ Á¦¾î¸¦ ¹þ¾î³­ ÀÛ¾÷¿¡
ÀÇÇØ ¿¹±âÄ¡ ¸øÇÑ ¼öÁ¤À¸·Î ÀÎÇÑ ¹®Á¦¸¦ ÇØ°áÇØ ÁØ´Ù.
volatileÅ°¿öµå´Â ¼öÇàÁßÀÎ ÇÁ·Î±×·¥ »Ó¸¸ ¾Æ´Ï¶ó ÀÎÅÍ·´Æ®¿¡
ÀÇÇØ ¾×¼¼½º µÉ ¼ö ÀÖ´Â º¯¼öÀÇ Àӽüº¿¡ ´ëÇØ ÄÄÆÄÀÏ·¯¿¡°Ô
¾Ë·ÁÁֹǷνá volatileÇü º¯¼ö°¡ Á¤È®ÇÑ °ªÀ» »ç¿ëÇÏ°Ô µÈ´Ù.

¹ØÀº MFC Help ¿¡ ÀÖ´Â ¿ø¹®ÀÌ´Ù.


1. volatile
volatile declarator

The volatile keyword is a type qualifier used to declare that an object can be modified in the program by something other than statements, such as the operating system, the hardware, or a concurrently executing thread.
The following example declares a volatile integer nVint whose value can be modified by external processes:

int volatile nVint;

Objects declared as volatile are not used in optimizations because their value can change at any time. The system always reads the current value of a volatile object at the point it is requested, even if the previous instruction asked for a value from the same object. Also, the value of the object is written immediately on assignment.
One use of the volatile qualifier is to provide access to memory locations used by asynchronous processes such as interrupt handlers.


2.Type of this Pointer

The this pointer's type can be modified in the function declaration by the const and volatile keywords. To declare a function as having the attributes of one or more of these keywords, use the cv-mod-list grammar.

Syntax

cv-mod-list:
cv-qualifier cv-mod-listopt

cv-qualifier:
const
volatile

Consider this example:

class Point
{
   unsigned X() const;
};


The preceding code declares a member function, X, in which the this pointer is treated as a const pointer to a const object. Combinations of cv-mod-list options can be used, but they always modify the object pointed to by this, not the this pointer itself. Therefore, the following declaration declares function X; the this pointer is a const pointer to a const object:

class Point
{
   unsigned X() __far const;
};


The type of this is described by the following syntax, where cv-qualifier-list can be const or volatile, class-type is the name of the class:

cv-qualifier-listopt class-type * const this

Table 8.2 explains more about how these modifiers work.

Table 8.2 Semantics of this Modifiers
< Modifier  Meaning >
<const>  Cannot change member data; cannot invoke member functions that are not const.
<volatile> Member data is loaded from memory each time it is accessed; disables certain optimizations.

It is an error to pass a const object to a member function that is not const. Similarly, it is an error to pass a volatile object to a member function that is not volatile.

Member functions declared as const cannot change member data -in such functions, the this pointer is a pointer to a const object.

Note Constructors and destructors cannot be declared as const or volatile. They can, however, be invoked on const or volatile objects.

HomePage Backward Forward Post Reply List
1998 by swindler