C++Builder Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
C++빌더 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
메신저 프로젝트
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C++빌더 Q&A
C++Builder Programming Q&A
[38484] 근데 왜 0x20으로 초기화하나요??
왕초보 [] 6179 읽음    2004-12-23 11:55
답변 잘봤습니다. 명확한 표현이네요.

근데 왜 0x20으로 초기화 하는지 이해가 안갑니다. NULL으로 초기화 해왔거든요.

무슨 이유인가요?


이현진 님이 쓰신 글 :
: (null) 님이 쓰신 글 :
: : Constructor를 쓰면 간단하지만, 그것을 사용하지 않는 방법을 물어보신거 같네요.
: :
: : 그 다음에 char 갯수만큼 memset으로 20으로 초기화 시키고...
: :
: : 포인터를 char 갯수만큼 이동시켜서 0으로 초기화하면 될거예요.
: :
: : memset( &m_sDummyData, 20, 26 );
: : memset( (&m_sDummyData)+26, 0, sizeof(int)*5 );
: :
: 위와 같은 초기화는 data alignment 문제로 인하여 제대로 초기화가 안될 수 있습니다.
: 컴파일러에 따라서, 그리고 컴파일러의 옵션에 따라서 구조체의 크기가 달라질 수 있습니다.
:
: 그냥, 아래 처럼 초기화 하는게 잘못된 초기화를 방지하겠죠..
:
: struct SDummyData // Dummy Data
: {
: public:
:     // ...
:     SDummyData();
: };
:
: SDummyData::SDummyData()
:     : nCoilThick(0), nCoilWidth(0), nCoilLength(0)
:     , nCoilWeight(0), nUseCount(0)
: {
:     memset(szStatusCode, 0x20, sizeof szStatusCode);
:     memset(szCCoilNo, 0x20, sizeof szCCoilNo);
:     memset(szDecisionKind, 0x20, sizeof szDecisionKind);
: }
:
: 참고)
:
: [MSDN Library - July 2004, C++ Language Reference align]
: Writing applications that use the latest processor instructions introduces some new constraints and issues. In particular, many new instructions require that data must be aligned to 16-byte boundaries. Additionally, by aligning frequently used data to the cache line size of a specific processor, you improve cache performance.
:
: [C++ Builder 6 Help, Data Alignment]
: The Data Alignment options let you choose how the compiler aligns data in stored memory.
: Word, double-word, and quadword alignment force  items to be aligned on memory addresses that are a multiple of the type chosen. Extra bytes are inserted in structures to ensure that members align correctly.
:
: Default = Double Word (32-bit)
:
: - Byte aligns to 8-bit boundaries.
: - Word aligns to 16-bit boundaries.
: - Double Word aligns to 32-bit boundaries.
:   Data with type sizes of less than 4 bytes are aligned on their type size.
: - Quad Word aligns to 64-bit boundaries.
:   Data with type sizes of less than 8 bytes are aligned on their type size.

+ -

관련 글 리스트
38460 [질문]struct 초기화 관련 홍성일 1651 2004/12/21
38463     Re:[질문]struct 초기화 관련 (null) 2662 2004/12/21
38467         Re:Re:[질문]struct 초기화 관련 이현진 2063 2004/12/22
38484             근데 왜 0x20으로 초기화하나요?? 왕초보 6179 2004/12/23
38496                 Re:근데 왜 0x20으로 초기화하나요?? 이현진 8216 2004/12/24
38486                 Re:Space... 2282 2004/12/23
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.