5 ms·
CERN actually does that with CLING for interactive HEP data science. https://root.cern/cling/ https://root.cern/cling/
by rahen 5y ago
CERN actually does that with CLING for interactive HEP data science.
https://root.cern/cling/ https://root.cern/cling/
- sigjuice 5y agoThanks! $ brew install cling $ cling ****************** CLING ****************** * Type C++ code and press enter to run it * * Type .q to exit * ******************************************* [cling]$ #include <stdio.h> [cling]$ #include <sys/utsname.h> [cling]$ struct utsname u; [cling]$ uname(&u); [cling]$ printf("%s %s %s\n", u.sysname, u.release, u.machine); Darwin 20.5.0 arm64
- rahen 5y agoYou can even use it interactively like ipython and get rid of the printf, as it automatically evaluates expressions. [cling]$ int i=21 (int) 21 [cling]$ i*2 (int) 42
- sigjuice 5y agoThanks! Is there a way to see strings nicely without printf? [cling]$ u.sysname (char [256]) "Darwin\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
- clappski 5y agoI 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.