CRT의 전역 상태Global state in the CRT
CRT (유니버설 C 런타임)의 일부 함수는 전역 상태를 사용 합니다.Some functions in the Universal C Runtime (UCRT) use global state. 예를 들어은 setlocale()
숫자 구분 기호, 텍스트 코드 페이지 등에 영향을 주는 전체 프로그램에 대 한 로캘을 설정 합니다.For example, setlocale()
sets the locale for the entire program, which affects the digit separators, text code page, and so on.
응용 프로그램 및 OS 간에는 응용 프로그램의 전역 상태가 공유 되지 않습니다.The UCRT's global state isn't shared between applications and the OS. 예를 들어 응용 프로그램에서를 호출 하 setlocale()
는 경우 C 런타임 또는 그 밖의 다른 방법을 사용 하는 모든 OS 구성 요소의 로캘에는 영향을 주지 않습니다.For example, if your application calls setlocale()
, it won't affect the locale for any OS components that uses the C run-time, or the other way around.
OS 특정 버전의 CRT 함수OS-specific versions of CRT functions
작업에서 전역 상태와 상호 작용 하는 함수에는 접두사가 인 "쌍" 함수가 있습니다 _o_
.In the UCRT, functions that interact with global state have a "twin" function, prefixed with _o_
. 예를 들면 다음과 같습니다.For example:
setlocale()
앱과 관련 된 전역 상태에 영향을 줍니다.setlocale()
affects global state specific to the app._o_setlocale()
앱이 아닌 모든 OS 구성 요소에서 공유 하는 전역 상태에 영향을 줍니다._o_setlocale()
affects global state shared by all OS components, but not apps.
이러한 "쌍" 함수 간의 유일한 차이점은 전역 CRT 상태를 읽거나 쓸 때 OS 특정 버전 (로 시작 하는 버전 _o_
)은 앱의 전역 상태 복사본 대신 전역 상태의 os 복사본을 사용 한다는 것입니다.The only difference between these "twin" functions is that when they read/write the global CRT state, the OS-specific versions (that is, the versions that start with _o_
) use the OS copy of global state instead of the app's copy of global state.
이러한 함수의 OS 특정 버전은에 ucrt.osmode.lib
있습니다.The OS-specific versions of these functions are in ucrt.osmode.lib
. 예를 들어 OS 특정 버전 setlocale()
은 _o_setlocale()
For example, the OS-specific version of setlocale()
is _o_setlocale()
앱의 CRT 상태에서 구성 요소의 CRT 상태를 격리 하는 방법에는 두 가지가 있습니다.There are two ways to isolate your component's CRT state from an app's CRT state:
- 컴파일러 옵션
/MT
(릴리스) 또는 (디버그)를 사용 하 여 구성 요소를 정적으로 연결/MTd
합니다.Statically link your component by using compiler options/MT
(release) or/MTd
(debug). 자세한 내용은 /md,/mt,/LD을 참조 하세요.For details, see /MD, /MT, /LD. 정적 링크를 통해 이진 크기가 크게 증가할 수 있습니다.Static linking can greatly increase binary size. - Windows 10 버전 2004부터 CRT에 동적으로 연결 되지만 OS 모드 내보내기 ( _o_로 시작 하는 함수)를 호출 합니다.Starting with Windows 10 version 2004, dynamically link to the CRT but call the OS-mode exports (the functions that begin with o). OS 모드 내보내기를 호출 하려면 정적으로 이전 처럼 링크 하지만 링커 옵션
/NODEFAULTLIB:libucrt.lib
(릴리스) 또는/NODEFAULTLIB:libucrtd.lib
(디버그)를 사용 하 여 정적 다중 경로를 무시 합니다.To call the OS-mode exports, statically link as before, but ignore the static UCRT by using linker option/NODEFAULTLIB:libucrt.lib
(release) or/NODEFAULTLIB:libucrtd.lib
(debug). 및ucrt.osmode.lib
를 링커 입력에 추가 합니다.And adducrt.osmode.lib
to the linker input. 자세한 내용은 /nodefaultlib (라이브러리 무시) 를 참조 하세요.See /NODEFAULTLIB (Ignore Libraries) for details.
참고
소스 코드에서를 쓰지 setlocale()
않고 작성 _o_setlocale()
합니다.In source code, write setlocale()
, not _o_setlocale()
. 에 연결 하면 ucrt.osmode.lib
링커가 함수의 OS 특정 버전으로 자동으로 대체 됩니다.When you link against ucrt.osmode.lib
, the linker will automatically substitute the OS-specific version of the function. 즉,는 setlocale()
로 대체 됩니다 _o_setlocale()
.That is, setlocale()
will be substituted with _o_setlocale()
.
에 연결 하면 ucrt.osmode.lib
앱 모드 에서만 사용할 수 있는 일부 사용이 중지 됩니다.Linking against ucrt.osmode.lib
disables some UCRT calls that are only available in app mode. 이러한 호출을 시도 하면 링크 오류가 발생 합니다.Attempting to call these will result in a link error.
앱/OS 분리의 영향을 받는 전역 상태Global state affected by app/OS separation
앱 및 OS 상태 분리의 영향을 받는 전역 상태는 다음과 같습니다.Global state affected by the separation of app and OS state includes:
- 로캘 데이터Locale data
- 신호로 설정 된 신호 처리기Signal handlers set by signal
- 종료 로 설정 된 종료 루틴Termination routines set by terminate
- errno 및 _doserrnoerrno and _doserrno
- Rand 및 srand 에서 사용 되는 난수 생성 상태Random number generation state used by rand and srand
- 사용자가 해제할 필요가 없는 버퍼를 반환 _ecvt 하는 함수: strtok, wcstok, _mbstok Tmpnam, _wtmpnam asctime, _wasctime gmtime, _gmtime32, _gmtime64 _fcvt _ecvt strerror, _strerror, _wcserror, __wcserrorFunctions that return a buffer that the user doesn't need to release: strtok, wcstok, _mbstok Tmpnam, _wtmpnam asctime, _wasctime gmtime, _gmtime32, _gmtime64 _fcvt _ecvt strerror, _strerror, _wcserror, __wcserror
- _Putch에서 사용 하는 버퍼 _putwchThe buffer used by _putch, _putwch
- _set_invalid_parameter_handler, _set_thread_local_invalid_parameter_handler_set_invalid_parameter_handler, _set_thread_local_invalid_parameter_handler
- _set_new_handler 및 _set_new_mode_set_new_handler and _set_new_mode
- fmodefmode
- 표준 시간대 정보Time zone information