standards

Is an empty initializer list valid C code?

梦想与她 提交于 2019-11-26 06:40:56
问题 It is common to use {0} to initialize a struct or an array but consider the case when the first field isn\'t a scalar type. If the first field of struct Person is another struct or array, then this line will result in an error ( error: missing braces around initializer ). struct Person person = {0}; At least GCC allows me to use an empty initializer list to accomplish the same thing struct Person person = {}; But is this valid C code? Also: Is this line guaranteed to give the same behavior, i

Does a dot have to be escaped in a character class (square brackets) of a regular expression?

流过昼夜 提交于 2019-11-26 06:00:48
问题 A dot . in a regular expression matches any single character. In order for regex to match a dot, the dot has to be escaped: \\. It has been pointed out to me that inside square brackets [] a dot does not have to be escaped. For example, the expression: [.]{3} would match ... string. Doesn\'t it, really? And if so, is it true for all regex standards? 回答1: In a character class (square brackets) any character except ^ , - , ] or \ is a literal. This website is a brilliant reference and has lots

Is `long` guaranteed to be at least 32 bits?

和自甴很熟 提交于 2019-11-26 05:56:15
问题 By my reading of the C++ Standard, I have always understood that the sizes of the integral fundamental types in C++ were as follows: sizeof(char) <= sizeof(short int) <= sizeof(int) <= sizeof(long int) I deduced this from 3.9.1/2: There are four signed integer types: “signed char”, “short int”, “int”, and “long int.” In this list, each type provides at least as much storage as those preceding it in the list. Plain ints have the natural size suggested by the architecture of the execution

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

杀马特。学长 韩版系。学妹 提交于 2019-11-26 05:53:18
问题 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

Address standardization within a database

怎甘沉沦 提交于 2019-11-26 05:39:07
问题 Working in MS Access 2013. Have a ton of locations/addresses which need to be standardized. Examples include addresses like: 500 W Main St 500 West Main St 500 West Main Street You get the point. I\'ve considered running a query that pulls all records where the left(7) or something characters exist more than once in the database, but there are obvious flaws in that logic. Is there a function or query or anything else that would help me generate a list of records whose addresses may exist

Why do compilers allow string literals not to be const?

痞子三分冷 提交于 2019-11-26 05:38:49
问题 And where are literals in memory exactly? (see examples below) I cannot modify a literal, so it would supposedly be a const char*, although the compiler let me use a char* for it, I have no warnings even with most of the compiler flags. Whereas an implicit cast of a const char* type to a char* type gives me a warning, see below (tested on GCC, but it behaves similarly on VC++2010). Also, if I modify the value of a const char (with a trick below where GCC would better give me a warning for),

Can a conforming C implementation #define NULL to be something wacky

五迷三道 提交于 2019-11-26 05:36:33
问题 I\'m asking because of the discussion that\'s been provoked in this thread. Trying to have a serious back-and-forth discussion using comments under other people\'s replies is not easy or fun. So I\'d like to hear what our C experts think without being restricted to 500 characters at a time. The C standard has precious few words to say about NULL and null pointer constants. There\'s only two relevant sections that I can find. First: 3.2.2.3 Pointers An integral constant expression with the

Computing length of a C string at compile time. Is this really a constexpr?

偶尔善良 提交于 2019-11-26 05:25:26
问题 I\'m trying to compute the length of a string literal at compile time. To do so I\'m using following code: #include <cstdio> int constexpr length(const char* str) { return *str ? 1 + length(str + 1) : 0; } int main() { printf(\"%d %d\", length(\"abcd\"), length(\"abcdefgh\")); } Everything works as expected, the program prints 4 and 8. The assembly code generated by clang shows that the results are computed at compile time: 0x100000f5e: leaq 0x35(%rip), %rdi ; \"%d %d\" 0x100000f65: movl $0x4

Are compilers allowed to eliminate infinite loops?

空扰寡人 提交于 2019-11-26 05:00:29
Can optimizing compiler delete infinite loops, which does not changes any data, like while(1) /* noop */; From analyzing a data flow graph compiler can derive, that such loop is "dead code" without any side effects. Is deleting of infinite loops prohibited by C90/C99 standards? Does C90 or C99 standards permit compiler to deleting such loops? Upd: "Microsoft C version 6.0 did essentially this optimization.", see link by caf. label: goto label; return 0; will be transformed to return 0; C11 clarifies the answer to this question, in the draft C11 standard section 6.8.5 Iteration statements added

What is currently the best way to get a favicon to display in all browsers that support Favicons?

泪湿孤枕 提交于 2019-11-26 04:59:39
问题 What is currently the best way to get a favicon to display in all browsers that currently support it? Please include: Which image formats are supported by which browsers. Which lines are needed in what places for the various browsers. 回答1: I go for a belt and braces approach here. I create a 32x32 icon in both the .ico and .png formats called favicon.ico and favicon.png . The icon name doesn't really matter unless you are dealing with older browsers. Place favicon.ico at your site root to