standard-library

where is stdin defined in c standard library?

给你一囗甜甜゛ 提交于 2019-11-29 06:44:26
I found this line in stdio.h : extern struct _IO_FILE *stdin; Based on this 'extern' keyword, i assume this is just a declaration. I wonder where is stdin defined and initialized? It's defined in the source code of your C library. You typically only need the headers for compilation, but you can find the source code for many open-source standard libraries (like glibc). In glibc, it's defined in libio/stdio.c as like this: _IO_FILE *stdin = (FILE *) &_IO_2_1_stdin_; Which is in turn defined using a macro in libio/stdfiles.c like this: DEF_STDFILE(_IO_2_1_stdin_, 0, 0, _IO_NO_WRITES); The

Where are the functions in the C standard library defined?

霸气de小男生 提交于 2019-11-29 05:33:39
I'm not interested in the source code, I want to know how the C compiler (GCC) actually finds the functions. As in, when the preprocessor sees that I've included stdio.h , where does it look to find the files that define the function bodies? Edit I should probably also say I'm using Ubuntu 12.04, but if there's a general answer, that would work too. Alex D gcc comes with (binary) object files ( not C source files) which contain implementations of all the standard C functions. When you use gcc to link object files into an executable file, the linker automatically includes the object files which

What are the rules for function pointers and member function pointers to Standard functions?

*爱你&永不变心* 提交于 2019-11-29 04:29:00
What are the existing rules for taking function pointers or member function pointers to Standard functions? For example, something like auto p = &std::string::size; Is this legal? Would it be more or less legal if I explicitly requested the correct type, so it would function even if there was an additional implementation-added overload of std::string::size ? Using the "correct" type doesn't make things better: Except for the virtual functions all functions in the standard C++ library can have additional arguments as long as these are defaulted. Since the functions can also be declared with

Does std::multiset guarantee insertion order?

天大地大妈咪最大 提交于 2019-11-29 03:49:19
I have a std::multiset which stores elements of class A . I have provided my own implementation of operator< for this class. My question is if I insert two equivalent objects into this multiset is their order guaranteed? For example, first I insert a object a1 into the set and then I insert an equivalent object a2 into this set. Can I expect the a1 to come before a2 when I iterate through the set? If no, is there any way to achieve this using multiset? In C++03 you are not guaranteed that insert and erase preserve relative ordering . However, this is changed in C++0x: n3092, §23.2.4/4: An

Does std::atomic<std::string> work appropriately?

橙三吉。 提交于 2019-11-29 00:55:41
I am reading through Anthony Williams' "C++ Concurrency in Action" and in Chapter 5, which talks about the new multithreading-aware memory model and atomic operations, and he states: In order to use std::atomic<UDT> for some user-defined UDT , this type must have a trivial copy assignment operator. As I understand it, this means that we can use std::atomic<UDT> if the following returns true: std::is_trivially_copyable<UDT>::value By this logic, we shouldn't be able to use std::string as a template argument for std::atomic and have it work correctly. However, the following code compiles and

What does the “c” mean in cout, cin, cerr and clog?

两盒软妹~` 提交于 2019-11-28 23:35:26
问题 What does the "c" mean in the cout, cin, cerr and clog names? I would say char but I haven't found anything to confirm it. 回答1: The "c" stands for "character" because iostreams map values to and from byte (char) representations. [Bjarne Stroustrup's C++ Style and Technique FAQ] 回答2: I originally guessed console , and this link confirmed it. But after seeing the quote from Stroustrup, it seems that's a misconception, and that the c stands for character . One thing in favor of that theory that

Compile-time reflection in C++1z? [closed]

匆匆过客 提交于 2019-11-28 21:07:27
There is a study group in the C++ standardization committee to provide compile-time reflection in C++1z or after. I would like to know what is exactly the purpose and how powerful the expected tools will be? For example will it be possible to name functions or classes using these tools? struct A {int f() {return 42;}}; struct B {int (std::reflect<A>::member<0>::declname)() {return 43;}}; // equivalent to struct B {int f() {return 43;}}; If it would not be as powerful as this, what the typical use cases will be? Reflection use cases are outlined in N3814: http://www.open-std.org/jtc1/sc22/wg21

Is there a standard java exception class that means “The object was not found”?

那年仲夏 提交于 2019-11-28 21:01:26
Consider a function of the following general form: Foo findFoo(Collection<Foo> foos, otherarguments) throws ObjectNotFoundException { for(Foo foo : foos){ if(/* foo meets some condition*/){ return foo; } } throw new ObjectNotFoundException(); } A concrete case, for example, would be: User findUserByName(Collection<User> users, String name) throws ObjectNotFoundException { for(User user : users){ if(user.getName().equals(name)){ return user; } } throw new ObjectNotFoundException(); } These functions throw an exception if the object is not found. I can create a custom exception class for this

C++11 Thread waiting behaviour: std::this_thread::yield() vs. std::this_thread::sleep_for( std::chrono::milliseconds(1) )

南笙酒味 提交于 2019-11-28 19:10:12
I was told when writing Microsoft specific C++ code that writing Sleep(1) is much better than Sleep(0) for spinlocking, due to the fact that Sleep(0) will use more of the CPU time, moreover, it only yields if there is another equal-priority thread waiting to run. However, with the C++11 thread library, there isn't much documentation (at least that I've been able to find) about the effects of std::this_thread::yield() vs. std::this_thread::sleep_for( std::chrono::milliseconds(1) ) ; the second is certainly more verbose, but are they both equally efficient for a spinlock, or does it suffer from

How can I tell if a Perl module is core or part of the standard install?

 ̄綄美尐妖づ 提交于 2019-11-28 17:24:12
How can I check if a Perl module is part of the core - i.e. it is part of the standard installation? I'm looking for: a command-line command: a Perl subroutine/function to check within code Perhaps the question should be: How can I tell what modules were originally provided with the specific Perl installation on a machine? (Actually, it is now asked as How can I tell what modules were originally provided with the specific Perl installation on a machine? .) Given that there now appears to not to be an overall Perl standard installation, at least the answer to this new question will tell me what