standards

UINT_MAX + 1 equals what?

删除回忆录丶 提交于 2019-12-18 03:33:16
问题 What is the defined behavior in C for UINT_MAX + 1u ? How safe is to assume it is zero? 回答1: From the standard (C11, 6.2.5/9, emphasis mine): [...] A computation involving unsigned operands can never overflow, because a result that cannot be represented by the resulting unsigned integer type is reduced modulo the number that is one greater than the largest value that can be represented by the resulting type . If UINT_MAX is 10 : (10 + 1) % (10 + 1) == 0 So, yes, it's safe to assume it's zero.

error: ISO C++ forbids in-class initialization of non-const static member

北城以北 提交于 2019-12-18 03:16:08
问题 this is the header file: employee.h #ifndef EMPLOYEE_H #define EMPLOYEE_H #include <iostream> #include <string> using namespace std; class Employee { public: Employee(const string &first, const string &last) Overloaded Constructor : firstName(first), firstName overloaded constructor lastName(last) lastName overloaded constructor { //The constructor start ++counter; it adds one plus per each object created; cout << "Employee constructor for " << firstName << ' ' << lastName << " called." <<

Are colons allowed in URLs?

萝らか妹 提交于 2019-12-18 02:09:09
问题 I thought using colons in URIs was "illegal". Then I saw that vimeo.com is using URIs like http://www.vimeo.com/tag:sample. What do you feel about the usage of colons in URIs? How do I make my Apache server work with the "colon" syntax because now it's throwing the "Access forbidden!" error when there is a colon in the first segment of the URI? 回答1: Colons are allowed in the URI path. But you need to be careful when writing relative URI paths with a colon since it is not allowed when used

Correct way to initialize HashMap and can HashMap hold different value types?

陌路散爱 提交于 2019-12-17 23:19:19
问题 So I have two questions about HashMap s in Java: What is the correct way to initialize a HashMap ? I think it might be best in my situation to use: HashMap x = new HashMap(); But Eclipse keeps suggesting that I use: HashMap<something, something> map = new HashMap(); Which is better? Can a HashMap hold different types of objects/data types as values? For example, would this work and be OK: map.put("one", 1); map.put("two", {1, 2}); map.put("three", "hello"); In the first put() , I want an int

How does the standards committee indicate the status of a paper under consideration?

不问归期 提交于 2019-12-17 23:18:56
问题 Does the C++ standards committee provide (on the open standard site or elsewhere) any indicatation of the status of the papers under consideration and indexed on the open-standards site? I am referring to the individual "papers" indicating potential changes to the standard, with associated discussion, as per the example below; I am not referring to the (published or draft) standard as a whole . For instance, how can I determine whether N3922 has been accepted or rejected? 回答1: For this

Does the C++ standard specify anything on the representation of floating point numbers?

纵饮孤独 提交于 2019-12-17 23:15:16
问题 For types T for which std::is_floating_point<T>::value is true , does the C++ standard specify anything on the way that T should be implemented? For example, does T has even to follow a sign/mantissa/exponent representation? Or can it be completely arbitrary? 回答1: From N3337: [basic.fundamental/8]: There are three floating point types: float, double, and long double. The type double provides at least as much precision as float, and the type long double provides at least as much precision as

What are the Constraints in Standard C?

﹥>﹥吖頭↗ 提交于 2019-12-17 22:49:50
问题 C standards talk about constraints , e. g. ISO/IEC 9899:201x defines the term constraint restriction, either syntactic or semantic, by which the exposition of language elements is to be interpreted and says in chapter Conformance If a ‘‘shall’’ or ‘‘shall not’’ requirement that appears outside of a constraint or runtime-constraint is violated, the behavior is undefined. In chapter Environment , Subsection Diagnostics it is said A conforming implementation shall produce at least one diagnostic

Default values in C++ initializer lists

筅森魡賤 提交于 2019-12-17 22:42:32
问题 I only just learned yesterday that specifying parameters to initializer list items is optional. However, what are the rules for what happens in this case? In the below example, will ptr be initialized to 0, toggle to false, and Bar default-constructed? I guess this question is sort of redundant, because there would be little point in initializer lists if unspecified argument values == undefined behavior. Could I also be pointed to the section of the C++ standard that states the behavior in

Difference between 'global' and 'static global'

谁说我不能喝 提交于 2019-12-17 21:47:57
问题 A global variable 's scope is in all the files, while a static global variable 's scope is just the file where it is declared. Why so? Where are global or static global variables stored in memory? 回答1: There is some confusion, since static in C can mean two different things. One is static storage duration, and the other is internal linkage. static used as a keyword on file-scope will give the function or object it is used with internal linkage. Internal linkage for a function or object means

What's the best way to format a phone number in Python?

一笑奈何 提交于 2019-12-17 20:04:04
问题 If all I have is a string of 10 or more digits, how can I format this as a phone number? Some trivial examples: 555-5555 555-555-5555 1-800-555-5555 I know those aren't the only ways to format them, and it's very likely I'll leave things out if I do it myself. Is there a python library or a standard way of formatting phone numbers? 回答1: for library: phonenumbers (pypi, source) Python version of Google's common library for parsing, formatting, storing and validating international phone numbers