Hacker News
new
|
past
|
comments
|
ask
|
show
|
jobs
|
submit
login
twoodfin
on Aug 8, 2024
|
parent
|
context
|
favorite
| on:
ICPP – Run C++ anywhere like a script
Good point, but if it’s a long string, 2/3 of the most common implementations would make the first word the c_str()-equivalent pointer:
https://devblogs.microsoft.com/oldnewthing/20240510-00/?p=10...
fluoridation
on Aug 8, 2024
[–]
So it's actually printing *(const char **)&s?
twoodfin
on Aug 8, 2024
|
parent
[–]
The first pointer-sized chunk of the string structure is a pointer to the C-string representation. So the cast works as written.
fluoridation
on Aug 8, 2024
|
root
|
parent
[–]
Well, no, because (const char *)str is nonsense, if str is an std::string.
twoodfin
on Aug 9, 2024
|
root
|
parent
[–]
Not to the debugger. If the first 8 bytes of the object referenced by str is a char* the debugger is perfectly capable of using it that way.
Guidelines
|
FAQ
|
Lists
|
API
|
Security
|
Legal
|
Apply to YC
|
Contact
Search:
https://devblogs.microsoft.com/oldnewthing/20240510-00/?p=10...