Closed xmh0511 closed 1 year ago
Your snippet shown above does not attempt to observe the presence of an object in the memory returned by malloc at all, so I'm not seeing a problem. In any case, implicitly created objects can be everywhere in the region of storage, not just at the beginning of the storage.
Note that objects have alignment requirements which restrict the placement of objects in memory.
Full name of submitter (unless configured in github; will be published with the issue): Jim X
In this example, which objects whose address is the start of the region allocated by
malloc
? [c.malloc] p2 saysIn C standard, the associated paragraphs say:
Anyway, [c.malloc] p4 only says
malloc
allocates the region as illustrated below, where0
designates the start of the region:"in the returned region of storage", as said in [c.malloc] p4, means the created object can be placed in anywhere as long as it is within the region. Could the object of class
A
be allocated at the bytes numbered by1
,2
,3
, orX
as long as the object is within the region? If not, which rule in the current draft says the address of the object of typeA
must be the byte numbered by0
? This issue was not clearly said in https://github.com/cplusplus/CWG/issues/98.The opinion in https://github.com/cplusplus/draft/issues/5630 is the subject here
That is to say, an object will have the address of the start of the region because it is a suitable object, instead of saying an object to be a suitable object should first satisfy its address at the start of the region. The chain of cause cannot be inverted.