Chapter 3 game software engineering Basics

Source: Internet
Author: User

3.2 C/C ++ data/code and memory

1 IEEE-754 floating point

32-bit floating point number. The first is the symbol bit, and then the 8-bit index and the 23-bit ending number. An offset of 127 is added to index storage, and the ending number is implicitly stored as 1.

An index of 255 indicates infinity.

2 Multi-byte values and Lexicographic orders

  A value greater than 8 bits is calledMultibyte.

  Small End:The minimum valid byte for storing multi-byte values is lower than the memory location.

  Big end:The maximum valid bytes for storing multi-byte values are smaller than the memory location.

  

Integer byte swap bit operation:

1 inline U32 swapU32 (U32 value) 2 {3     return ( (value & 0x000000FF) << 24)
4 | ( (value & 0x0000FF00) << 8)5 | ( (value & 0x00FF0000) >> 8)6 | ( (value & 0xFF000000) >> 24);7 }

Floating Point byte exchange:

 1 union U32F32 { 2     U32 m_asU32; 3     F32 m_asF32; 4 }; 5  6 inline F32 swapF32 (F32 value) { 7     U32F32 u; 8     u.m_asF32 = value; 9     u.m_asU32 = swapU32 (u.m_asU32);10     return u.m_asF32;11 }

3. Declaration, definition and connection specifications

  LinkerThe main function is to solve external references. Only two types of errors can be reported:

1) if the target referenced by extern is not found, the error "unresolved external symbol" is returned ";

2) locate two or more entities with the same name (functions or variables) and report the error "Multiply defined symbol ".

It can be declared multiple times, but can be defined only once. If it is defined multiple times in the same file, the compiler reports an error. If it is repeatedly defined in multiple files, the linker reports an error. Therefore,Place definitions in header filesIs dangerous. If multiple files are included, an error will occur.

  Inline Function: The Inline Function expands where it is called and copies its machine code.Therefore, if inline functions are used in multiple files, they should be placed in the header file.

Link specifications: static, internal, and external connections.

4 C/C ++ memory Layout

  Alignment: Whether the memory address of the data object is a multiple of the size of the aligned bytes.

  

Chapter 3 game software engineering Basics

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.