standard-library

Is strncpy() a specialization of memcpy()?

陌路散爱 提交于 2019-12-20 04:40:29
问题 Just curious to know (as we use these functions often). I don't see any practical difference between strncpy() and memcpy(). Isn't it worth to say that effectively, char* strncpy (char *dst, const char *src, size_t size) { return (char*)memcpy(dst, src, size); } Or am I missing any side effect? There is one similar earlier question, but couldn't find an exact answer. 回答1: There is a difference, see this part of the strncpy page you linked to (emphasis mine): Copies the first num characters of

Is the Python standard library really standard?

早过忘川 提交于 2019-12-19 19:49:40
问题 Is the Python standard library standard in the sense that if Python is installed, then the standard library is installed too? The documentation reads For Unix-like operating systems Python is normally provided as a collection of packages, so it may be necessary to use the packaging tools provided with the operating system to obtain some or all of the optional components. The standard library index only lists as optional the "Optional Operating System Services", as far as I can tell. So, is

Why is the c++ standard library not working?

此生再无相见时 提交于 2019-12-19 09:57:33
问题 I've been trying to get my program that I downloaded from my schools server to run offline on my mac. I tried updating GCC by following tutorials and for some reason the tutorials didn't work even though I was using the commands given. Now when I compile.. I get an error saying that is not found.. I don't get it. I've updated Xcode.. followed tons of tutorials.. and I still can't get the thing to run! Why is it saying that random is not found, causing a fatal error? Thanks Error: DungeonLevel

How does stringstream work internally?

喜你入骨 提交于 2019-12-19 03:15:50
问题 I'm asking in context of performance. Is stringstream simply a string/vector, so writing to it may result in its whole content being copied to a bigger chunk of memory, or is it done in a more tricky way (say, a list of strings or whatever)? 回答1: It's up to the standard library vendor how to implement stringstream (or any library feature for that matter). You can look at the sstream header shipped with your compiler to see how it's implemented there. That much on the theoretical side... As

How does printf work internally? [duplicate]

我们两清 提交于 2019-12-18 19:09:45
问题 This question already has an answer here : how printf works internally.? [duplicate] (1 answer) Closed 6 years ago . I am curious as to how printf works internally within Linux. I don't understand how it writes data to STDOUT . After a bit of searching for the internals, I downloaded glibc and took a look at the source code: __printf (const char *format, ...) { va_list arg; int done; va_start (arg, format); done = vfprintf (stdout, format, arg); va_end (arg); return done; } After finding this

Force import module from Python standard library instead of PYTHONPATH default

人走茶凉 提交于 2019-12-18 19:01:49
问题 I have a custom module in one of the directories in my PYTHONPATH with the same name as one of the standard library modules, so that when I import module_name , that module gets loaded. If I want to use the original standard library module, is there any way to force Python to import from the standard library rather than from the PYTHONPATH directory, short of renaming the custom module and changing every reference to point to the new name? 回答1: The ideal solution would be to rename your

What is the result of `strtod(“3ex”, &end)` supposed to be? What about `sscanf`?

别来无恙 提交于 2019-12-18 13:28:25
问题 In my experiments this expression double d = strtod("3ex", &end); initializes d with 3.0 and places end pointer at 'e' character in the input string. This is exactly as I would expect it to behave. The 'e' character might look as a beginning of the exponent part, but since the actual exponent value (required by 6.4.4.2) is missing, that 'e' should be treated as a completely independent character. However, when I do double d; char c; sscanf("3ex", "%lf%c", &d, &c); I notice that sscanf

How can pointers be totally ordered?

和自甴很熟 提交于 2019-12-18 12:15:37
问题 Pointers in C++ may in general only be compared for equality. By contrast, less-than comparison is only allowed for two pointers that point to subobjects of the same complete object (e.g. array elements). So given T * p, * q , it is illegal in general to evaluate p < q . The standard library contains functor class templates std::less<T> etc. which wrap the built-in operator < . However, the standard has this to say about pointer types (20.8.5/8): For templates greater , less , greater_equal ,

Embed Python3 without standard library

大憨熊 提交于 2019-12-18 10:58:51
问题 EDIT: I have asked an opposing question here: How to embed Python3 with the standard library A solution for Python2 is provided here: Is it possible to embed python without the standard library? However, Python3 fails on Py_Initialize(); with: Fatal Python error: Py_Initialize: unable to load the file system codec ImportError: No module named 'encodings' This makes sense because py3 source files are utf-8 by default. So it seems that it requires an external binary just in order to parse py3

When should I use std::bind?

人走茶凉 提交于 2019-12-18 10:39:11
问题 Every time I need to use std::bind , I end up using a lambda instead. So when should I use std::bind ? I just finished removing it from one codebase, and I found that lambdas were always simpler and clearer than std::bind . Isn't std::bind completely unnecessary? Shouldn't it be deprecated in the future? When should I prefer std::bind to lambda functions? (There has to be a reason that it got into the standard at the same time as lambdas.) I've also noticed that more and more people are