4 ms·
I imagine if you printed an actual string it would look as you expect, issue is that you're printing a char array and not a C++ std::string/_view
by clappski 5y ago
I imagine if you printed an actual string it would look as you expect, issue is that you're printing a char array and not a C++ std::string/_view
- sigjuice 5y agoSure, but I’d expect the interpreter to have some smarts to do the right thing within reason.
- clappski 5y agoBut a char[] could be binary data for all the tool knows, do you want it to do a buffer overflow and end up bricking your computer? std::string etc. exist exactly because char[] is unsafe for holding strings unless you carry around a size.
- deleted 5y ago[deleted]
- sigjuice 5y agoThere is a size in the example I posted above. [cling]$ u.sysname (char [256])
- rahen 5y agoIndeed, this is the expected behavior with C arrays, regardless their type. The solutions are either to use a C++ std::string as you mentioned, or a typedef struct with a length property.
- sigjuice 5y agostruct utsname is what it is. For me the appeal for something like cling would be doing quick experiments without any boilerplate.