standard-library

How do the standard C library and system calls work together?

半城伤御伤魂 提交于 2019-12-07 04:53:02
问题 I recently got interested about inner workings of compilers, standard libraries and kernels. While I was searching for the source code of the standard C library, I came across with Glibc. But what it says in Glibc's official website is: the library which defines the ''system calls'' and other basic facilities such as open, malloc, printf, exit... So I guess that Glibc actually doesn't provide the source code of the standard C library, but instead provides the system calls for those functions,

Retrieve wall-time in Python using the standard library?

不羁岁月 提交于 2019-12-07 02:18:27
问题 How can I retrieve wall-time in Python using the standard library? This question, and this question would suggest that something like clock_gettime(CLOCK_MONOTONIC_RAW) or /proc/uptime are most appropriate on Linux. On Windows, time.clock() has the desired effect. I would use time.time(), but the function is not guaranteed to return monotonically (and linearly) increasing time values. 回答1: Victor Stinner wrote a Python implementation of a monotonic timer. See http://bugs.python.org/issue10278

make_unique arrays, original proposal vs. final

我只是一个虾纸丫 提交于 2019-12-06 17:38:57
问题 Stephan T Lavavej's initial proposal for make_unique was N3588 It included the following functions: make_unique<T>(args...) make_unique_default_init<T>() make_unique<T[]>(n) make_unique_default_init<T[]>(n) make_unique_value_init<T[]>(n, args...) make_unique_auto_size<T[]>(args...) However, the final propsal, N3656, only includes make_unique (both forms). I am unable to find any discussion on the other forms of the function. I read the minutes of the Bristol meeting, but they don't even

Using Python's max function when you have a variable named max?

回眸只為那壹抹淺笑 提交于 2019-12-06 12:02:47
问题 Python includes the built in max() function. However, despite it being built in it is not a keyword. That is to say, you are allowed to do max=4 . This makes sense since the maximum of something comes up a lot. But! If you use max as a variable, then it disables use of the max function in that scope. So if you do: max = 4 max(1, 2) You will get an error of int object not callable . Again, makes sense. But is there any way to specify that you would like the max function? Like a std.max() ?

Standard c++ library linking

泪湿孤枕 提交于 2019-12-05 21:05:26
I'm trying to understand when does standard library linking to my own binary. I've written the following: #include <stdio.h> double atof(const char*); int main(){ const char * v="22"; printf("Cast result is %f", atof(v)); } It's compiling successful with g++ -c main.cpp , but when I'm linking just created object file I've an error. Error descriptio is: /tmp/ccWOPOS0.o: In function `main': main.cpp:(.text+0x19): undefined reference to `atof(char const*)' collect2: error: ld returned 1 exit status But I don't understand why this error is caused? I think that the standard c++ library

Going through the source code for the prelude brings up weirdness

霸气de小男生 提交于 2019-12-05 14:36:06
问题 I was looking for the definition of seq and came across this weirdness. Why do all these functions have the same/similar definitions? seq :: a -> b -> b seq = let x = x in x inline :: a -> a inline = let x = x in x lazy :: a -> a lazy = let x = x in x There are many more with this definition in the source code. What's going on? 回答1: What's going on is that these functions cannot be implemented in Haskell, but they should appear in the docs. Since haddock needs a syntactically correct (and

Boost's lexical_cast From double to string Precision

杀马特。学长 韩版系。学妹 提交于 2019-12-05 13:43:41
I'm working with a library that unfortunately uses boost::lexical_cast to convert from a double to a string . I need to be able to definitively mirror that behavior on my side, but I was hopping to do so without propagating boost . Could I be guaranteed identical behavior using to_string , sprintf , or some other function contained within the standard? The boost code ends up here: bool shl_real_type(double val, char* begin) { using namespace std; finish = start + #if defined(_MSC_VER) && (_MSC_VER >= 1400) && !defined(__SGI_STL_PORT) && !defined(_STLPORT_VERSION) sprintf_s(begin,

How do the standard C library and system calls work together?

扶醉桌前 提交于 2019-12-05 09:58:14
I recently got interested about inner workings of compilers, standard libraries and kernels. While I was searching for the source code of the standard C library, I came across with Glibc. But what it says in Glibc's official website is: the library which defines the ''system calls'' and other basic facilities such as open, malloc, printf, exit... So I guess that Glibc actually doesn't provide the source code of the standard C library, but instead provides the system calls for those functions, and then the kernel takes care of them, am I right? I would like to learn more about those things. For

Retrieve wall-time in Python using the standard library?

我的梦境 提交于 2019-12-05 04:31:30
How can I retrieve wall-time in Python using the standard library? This question, and this question would suggest that something like clock_gettime(CLOCK_MONOTONIC_RAW) or /proc/uptime are most appropriate on Linux. On Windows, time.clock() has the desired effect. I would use time.time() , but the function is not guaranteed to return monotonically (and linearly) increasing time values. Victor Stinner wrote a Python implementation of a monotonic timer . See http://bugs.python.org/issue10278 for the discussion and the docs for the upcoming 3.3 release referencing the new feature (coded in C).

How do I use C++ STL containers in My iPhone App?

一笑奈何 提交于 2019-12-05 03:59:05
I'd like to use an STL set in my iPhone app (which is written in Objective-C in XCode). How do I include set and/or use the standard namespace? In C++ I'd do this: #include<set> using namespace std; // use the set<T> somewhere down here... How can I do this in Objective-C? Just rename your source file so it ends in .mm and it should trigger the Objective-C++ front-end; you can then mix Objective-C and C++ in it. More information here . STL is not directly supported in objective-C. There appear to be several projects though that are attempting to port STL to objective-C. Objectivelib is one