Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      Memory model

      From cppreference.com
      <cpp‎ |language
       
       
      C++ language
      General topics
      Flow control
      Conditional execution statements
      Iteration statements (loops)
      Jump statements
      Functions
      Function declaration
      Lambda function expression
      inline specifier
      Dynamic exception specifications(until C++17*)
      noexcept specifier(C++11)
      Exceptions
      Namespaces
      Types
      Specifiers
      constexpr(C++11)
      consteval(C++20)
      constinit(C++20)
      Storage duration specifiers
      Initialization
      Expressions
      Alternative representations
      Literals
      Boolean -Integer -Floating-point
      Character -String -nullptr(C++11)
      User-defined(C++11)
      Utilities
      Attributes(C++11)
      Types
      typedef declaration
      Type alias declaration(C++11)
      Casts
      Memory allocation
      Classes
      Class-specific function properties
      Special member functions
      Templates
      Miscellaneous
       
       

      Defines the semantics of computer memory storage for the purpose of the C++ abstract machine.

      The memory available to a C++ program is one or more contiguous sequences ofbytes. Each byte in memory has a uniqueaddress.

      Contents

      [edit]Byte

      Abyte is the smallest addressable unit of memory. It is defined as a contiguous sequence of bits, large enough to hold

      • the value of anyUTF-8 code unit (256 distinct values) and of
      (until C++23)
      (since C++23)

      Similar to C, C++ supports bytes of sizes 8 bits and greater.

      Thetypeschar,unsignedchar, andsignedchar use one byte for both storage andvalue representation. The number of bits in a byte is accessible asCHAR_BIT orstd::numeric_limits<unsignedchar>::digits.

      [edit]Memory location

      Amemory location is the storage occupied by theobject representation of either an object ofscalar type that is not abit-field, or the largest contiguous sequence of bit-fields of non-zero length.

      Note: Various features of the language, such asreferences andvirtual functions, might involve additional memory locations that are not accessible to programs but are managed by the implementation.

      struct S{char a;// memory location #1int b:5;// memory location #2int c:11,// memory location #2 (continued):0,        d:8;// memory location #3struct{int ee:8;// memory location #4} e;} obj;// The object “obj” consists of 4 separate memory locations

      [edit]Defect reports

      The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

      DRApplied toBehavior as publishedCorrect behavior
      CWG 1953C++98objects occupying the same storage were
      considered as different memory locations
      memory location
      now refers to storage

      [edit]See also

      C documentation forMemory model
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/language/memory_model&oldid=179719"

      [8]ページ先頭

      ©2009-2025 Movatter.jp