c99

Skipping switch cases via false loop is a valid operation?

北慕城南 提交于 2020-01-04 04:18:09
问题 Would this be legal code or breaking any rules? switch (expr) { do { case 6: /*...*/ if (/*...*/) break; case 7: /*...*/ } while (0); case 9: /*...*/ break; default: break; } Would this be a legal way of executing case 6 followed by case 7 but only if some conditions are met? Or would this lead into undefined behavior and lets nasal dragons come out of the switch? p.s. my Question is refering to c99. EDIT: What i want to do is the following: assume, case 9, has to be executed in everycase. If

std::remquo purpose and usage?

时光毁灭记忆、已成空白 提交于 2020-01-04 02:38:05
问题 What is the purpose of the std::remquo function? What is an example of when you would use it instead of the regular std::remainder function? 回答1: remquo first appeared in C99 before being in C++ and here is what the C99 rationale says about it: The remquo functions are intended for implementing argument reductions which can exploit a few low-order bits of the quotient. Note that x may be so large in magnitude relative to y that an exact representation of the quotient is not practical. 回答2:

Variable Length Array with length 0?

笑着哭i 提交于 2020-01-03 17:54:08
问题 In C, an array normally isn't allowed to have size 0 (unless I use the one or other compiler-side extension). OTOH, there are VLAs whose length might turn out to be 0. Are they allowed? I am talking about the following code: void send_stuff() { char data[4 * !!flag1 + 2 * !!flag2]; uint8_t cursor = 0; if (flag1) { // fill 4 bytes of data into &data[cursor] cursor += 4; } if (flag2) { // fill 2 bytes of data into &data[cursor] cursor += 2; } } The result is a data array with a length of 0, 2,

Can unsigned integer incrementation lead to undefined defined behavior?

点点圈 提交于 2020-01-03 16:00:55
问题 After reading the 32 bit unsigned multiply on 64 bit causing undefined behavior? question here on StackOverflow, I began to ponder whether typical arithmetic operations on small unsigned types could lead to undefined behavior according to the C99 standard. For example, take the following code: #include <limits.h> ... unsigned char x = UCHAR_MAX; unsigned char y = x + 1; The x variable is initialized to the maximum magnitude for the unsigned char data type. The next line is the issue: the

Can unsigned integer incrementation lead to undefined defined behavior?

倾然丶 夕夏残阳落幕 提交于 2020-01-03 16:00:49
问题 After reading the 32 bit unsigned multiply on 64 bit causing undefined behavior? question here on StackOverflow, I began to ponder whether typical arithmetic operations on small unsigned types could lead to undefined behavior according to the C99 standard. For example, take the following code: #include <limits.h> ... unsigned char x = UCHAR_MAX; unsigned char y = x + 1; The x variable is initialized to the maximum magnitude for the unsigned char data type. The next line is the issue: the

What ABI, if any, restricts the size of [u]intmax_t?

烈酒焚心 提交于 2020-01-03 07:22:32
问题 Starting with the 1999 edition, the ISO C standard defines a standard header <stdint.h> which defines, among other things, the typedefs intmax_t and uintmax_t . These designate, respectively, "a (signed|unsigned) integer type capable of representing any value of any (signed|unsigned) integer type". For example, if, as is typical, the widest signed and unsigned integer types are long long int and unsigned long long int , both of which are typically 64 bits, then intmax_t and uintmax_t might be

Are there float and double types with fixed sizes in C99?

限于喜欢 提交于 2020-01-02 03:53:19
问题 C99 states integer types like uint32_t, int16_t etc, where it's easy to see the number of bits used. Good to know in for instance embedded programming. I have not found any similar types for floating point values. Is there a standard? If not, why? 回答1: I found the answer in Any guaranteed minimum sizes for types in C? Quoting Jed Smith (with corrected link to C99 standard): Yes, the values in float.h and limits.h are system dependent. You should never make assumptions about the width of a

How to do an explicit fall-through in C

给你一囗甜甜゛ 提交于 2020-01-01 23:56:32
问题 The newer versions of gcc offer the Wimplicit-fallthrough , which is great to have for most switch statements. However, I have one switch statement where I want to allow fall throughs from all case-statements. Is there a way to do an explicit fall through? I'd prefer to avoid having to compile with Wno-implicit-fallthrough for this file. EDIT: I'm looking for a way to make the fall through explicit (if it's possible), not to turn off the warning via a compiler switch or pragma. 回答1: Use _

Does C99/C11 restrict type qualifier imply anything for functions without definition?

本小妞迷上赌 提交于 2020-01-01 13:15:58
问题 Suppose we have a function declaration for which we do not have access to its definition: void f(int * restrict p, int * restrict q, int * restrict r); Since we do not know how the pointers will be accessed, we cannot know if a call will trigger undefined behavior or not -- even if we are passing the same pointer, like the example at 6.7.3.1.10 explains: The function parameter declarations: void h(int n, int * restrict p, int * restrict q, int * restrict r) { int i; for (i = 0; i < n; i++) p

Flexible array member (c99) inside a structure

我是研究僧i 提交于 2019-12-31 04:14:09
问题 I've being using this code a while now, and it works fine, but it gave me some headache to implement it. It uses Flexible Array Member (FAM) aka Struct Hack. Now that C99 has the possibility of using Variable Length Array (VLA), I wonder how can I take advantage in this piece? typedef struct nO { int oper; /* some operator */ int nops; /* number of args */ struct nO *ptn[1]; /* expansible array <=== HERE */ } nodoOper; nodoOper *operator(int o, int n, ...) { va_list ap; nodoOper *tn; size_t