standards

Standard C library in mingW

我的梦境 提交于 2019-11-26 16:36:16
问题 I have installed mingW to use gcc, platform windows 7. I am trying to locate the standard C library libc.a in mingW folder. no luck.. is it stored in some other name? 回答1: MinGW does not build against glibc, it builds against msvcrt. As such, it uses libmsvcrtXX.a instead. 来源: https://stackoverflow.com/questions/6394512/standard-c-library-in-mingw

Is right shift undefined behavior if the count is larger than the width of the type?

半世苍凉 提交于 2019-11-26 16:35:50
I just checked the C++ standard. It seems the following code should NOT be undefined behavior : unsigned int val = 0x0FFFFFFF; unsigned int res = val >> 34; // res should be 0 by C++ standard, // but GCC gives warning and res is 67108863 And from the standard: The value of E1 >> E2 is E1 right-shifted E2 bit positions. If E1 has an unsigned type or if E1 has a signed type and a non-negative value, the value of the result is the integral part of the quotient of E1/2^E2. If E1 has a signed type and a negative value, the resulting value is implementation-defined. According to the standard, since

Why does C++ output negative numbers when using modulo?

时间秒杀一切 提交于 2019-11-26 16:31:56
Math : If you have an equation like this: x = 3 mod 7 x could be ... -4, 3, 10, 17, ..., or more generally: x = 3 + k * 7 where k can be any integer. I don't know of a modulo operation is defined for math, but the factor ring certainly is. Python : In Python, you will always get non-negative values when you use % with a positive m : #!/usr/bin/python # -*- coding: utf-8 -*- m = 7 for i in xrange(-8, 10 + 1): print(i % 7) Results in: 6 0 1 2 3 4 5 6 0 1 2 3 4 5 6 0 1 2 3 C++: #include <iostream> using namespace std; int main(){ int m = 7; for(int i=-8; i <= 10; i++) { cout << (i % m) << endl; }

Can we apply content not explicitly cited from the normative references to the C++ standard?

好久不见. 提交于 2019-11-26 16:24:15
问题 In the C++11 standard( closest draft is N3337 ) section 1.2 Normative references says: The following referenced documents are indispensable for the application of this document. For dated references, only the edition cited applies. For undated references, the latest edition of the referenced document (including any amendments) applies. but there are no guidelines on how to apply the references. The easy cases are when the C++11 explicitly refers back to a reference, for example in section 3.9

Does printf(“%x”,1) invoke undefined behavior?

孤街醉人 提交于 2019-11-26 16:18:41
According to the C standard (6.5.2.2 paragraph 6) If the expression that denotes the called function has a type that does not include a prototype, the integer promotions are performed on each argument, and arguments that have type float are promoted to double. These are called the default argument promotions. If the number of arguments does not equal the number of parameters, the behavior is undefined. If the function is defined with a type that includes a prototype, and either the prototype ends with an ellipsis (, ...) or the types of the arguments after promotion are not compatible with the

C++ Modules - why were they removed from C++0x? Will they be back later on?

戏子无情 提交于 2019-11-26 15:50:46
I just discovered this old C++0x draft about modules in C++0x. The idea was to get out of the current .h/.cpp system by writing only .cpp files which would then generate module files during compilation, which would then in turn be used by the other .cpp files. This looks like a really great feature. But my question is: why did they remove it from C++0x? Was it because of too many technical difficulties? Lack of time? And do you think they will consider working on it for an ulterior version of C++? From the State of C++ Evolution (Post San Francisco 2008) , the Modules proposal was categorized

Is there a way to access the underlying container of STL container adaptors?

梦想与她 提交于 2019-11-26 15:23:18
Is there a standard way to access the underlying container of stack , queue , priority_queue ? I found a method called : _Get_container() in VS2008 implementation of stack and queue , but no one for priority_queue ! I think it is not standard anyway. Also, I know it is a silly question! where can I find official documentation of the standard library ? Just for clarification, I wasn't trying to mess up with the underlying container. All what I was trying to do is this : template <class Container> std::ostream& printOneValueContainer(std::ostream& outputstream, Container& container) { Container:

Why both clang and gcc only give a warning when there is a space after backslash if C standard says that whitespace is forbidden?

痞子三分冷 提交于 2019-11-26 14:49:54
问题 When compiling the following snippet, both gcc and clang only issue a warning. Notice space after \ next to int : #include <stdio.h> #include <stdlib.h> int main(void) { int \ a = 10; printf("%d\n", a); } gcc: main.c:7:6: warning: backslash and newline separated by space [enabled by default] clang: main.c:7:7: warning: backslash and newline separated by space int ^ In c99 standard in 5.1.1.2 it says: Each instance of a backslash character () immediately followed by a new-line character is

Are there any suggestions for developing a C# coding standards / best practices document? [closed]

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-26 14:48:25
I'm a recent AI graduate (circa 2 years) working for a modest operation. It has fallen to me (primarily as I'm the first 'adopter' in the department) to create a basic (read useful?) C# coding standards document. I think I should explain that I'm probably the most junior software engineer going, but I'm looking forward to this task as hopefully I might actually be able to produce something half usable. I've done a pretty extensive search of the Internet and read articles on what a coding standards document should / should not contain. This seems like a good as place as any to ask for some

void, VOID, C and C++

房东的猫 提交于 2019-11-26 14:45:14
问题 I have the following code: typedef void VOID; int f(void); int g(VOID); which compiles just fine in C (using gcc 4.3.2 on Fedora 10). The same code compiled as C++ gives me the following error: void.c:3: error: ‘<anonymous>’ has incomplete type void.c:3: error: invalid use of ‘VOID’ Now, this is something in external library and I would like the owner to fix that problem. So I have a question - does C++ standard forbids this construct? Could you give me a pointer/citation? The only thing I