2

Mike Miller says in 240. Uninitialized values and undefined behavior:

The wording in 3.9.1 [basic.fundamental] was carefully crafted to allow use of unsigned char to access uninitialized data so that memcpy and such could be written in C++ without undefined behavior

What is meant by that? Why would one want to access uninitialized data?

3
  • @chac yes, to initialize it in other words. Commented Nov 2, 2012 at 7:54
  • Weird, I don’t think this passage would actually be necessary, one could always use placement-new to construct into uninitialised values. Commented Nov 2, 2012 at 8:04
  • @chac when you write into, do you use a pointer to do so? This pointer would then be initialized. Commented Nov 2, 2012 at 12:02

2 Answers 2

1

When you're copying a struct which contains padding, memcpy will copy the padding too. Generally that padding is uninitialized.

Sign up to request clarification or add additional context in comments.

Comments

0

It means that it is still possible to access memory not initialized by an object constructor (which is the way intended for C++). We can use unsigned char (or byte) to point to raw memory chunks.

Objects are what you should handle, but you can still see memory the way it is.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.