c99

UL suffix vs uint32_t cast

时光毁灭记忆、已成空白 提交于 2021-02-18 22:13:13
问题 I have to define constants like this : #define MY_CONSTANT 0xBEEF I want to be sure that my constant will be considered 32 bits. I have can use a (uint32_t) cast like this : #define MY_CONSTANT (uint32_t)0xBEEF Or a UL suffix like this : #define MY_CONSTANT 0xBEEFUL Are these two versions fully equivalent? I would say no, as UL is the equivalent of unsigned long and unsigned long length may depend on CPU. The C99 standard ensures that an uint32_t integer is 32 bits, but I don't think it

UL suffix vs uint32_t cast

六眼飞鱼酱① 提交于 2021-02-18 22:12:52
问题 I have to define constants like this : #define MY_CONSTANT 0xBEEF I want to be sure that my constant will be considered 32 bits. I have can use a (uint32_t) cast like this : #define MY_CONSTANT (uint32_t)0xBEEF Or a UL suffix like this : #define MY_CONSTANT 0xBEEFUL Are these two versions fully equivalent? I would say no, as UL is the equivalent of unsigned long and unsigned long length may depend on CPU. The C99 standard ensures that an uint32_t integer is 32 bits, but I don't think it

Can an implementation that has sizeof (int) == 1 “fully conform”? [duplicate]

吃可爱长大的小学妹 提交于 2021-02-16 06:13:36
问题 This question already has answers here : Can sizeof(int) ever be 1 on a hosted implementation? (8 answers) Closed 5 years ago . According to the C standard, any characters returned by fgetc are returned in the form of unsigned char values, "converted to an int " (that quote comes from the C standard, stating that there is indeed a conversion). When sizeof (int) == 1 , many unsigned char values are outside of range. It is thus possible that some of those unsigned char values might end up being

unknown type name 'siginfo_t' with Clang using _POSIX_C_SOURCE 2, why?

走远了吗. 提交于 2021-02-08 15:34:11
问题 Update Turnes out my lecturer will accept code written to the GNU99 standard, so, as User1 pointed out, I used _GNU_SOURCE at the beginning of my program. (See man feature_test_macros for more info.) Thanks for helping me understand! On Ubuntu 13.10 with Clang 3.4, GCC 4.8.1, I am doing an assignment which requires me to use the C99 standard. (I also have GNUstep installed from SVN) WRT GCC, I think I have 4 versions installed in these folders: /usr/lib/gcc/x86_64-linux-gnu/4.7 /usr/lib/gcc

How to pass infinity values to a function and test the result

给你一囗甜甜゛ 提交于 2021-02-08 08:16:19
问题 I have this function: #include <complex.h> complex double f(complex double x, complex double y) { return x*y; } I would like to call it with x = inf + i inf and y = i inf and see what the result is. In particular I want to test if the result is an infinity value (as it should be) or if it is NaN + iNaN . The reason for this is to test different C compilers. How do you do this in C? 回答1: I would add an intermediate check, too: #include <stdio.h> #include <stdlib.h> #include <complex.h>

C99 floating point intermediate results

折月煮酒 提交于 2021-02-08 07:51:29
问题 As per the C99 standard: 6.3.1.8.2 : The values of floating operands and of the results of floating expressions may be represented in greater precision and range than that required by the type; the types are not changed thereby.52)> However, outside the scope of Annex F, we have: 5.2.4.2.2.7 : The values of operations with floating operands and values subject to the usual arithmetic conversions and of floating constants are evaluated to a format whose range and precision may be greater than

C99 floating point intermediate results

戏子无情 提交于 2021-02-08 07:51:10
问题 As per the C99 standard: 6.3.1.8.2 : The values of floating operands and of the results of floating expressions may be represented in greater precision and range than that required by the type; the types are not changed thereby.52)> However, outside the scope of Annex F, we have: 5.2.4.2.2.7 : The values of operations with floating operands and values subject to the usual arithmetic conversions and of floating constants are evaluated to a format whose range and precision may be greater than

Why can't I “goto default;” or “goto case x;” within a switch selection structure?

会有一股神秘感。 提交于 2021-02-07 11:22:49
问题 Section 6.8.1 of C11 or C99, or section 3.6.1 of C89 all seem to indicate that default and case x (where x is some constant-expression ) are examples of labeled statements, along-side identifier: -style labels that are suitable for use with goto . I'm aware that I could simply place an identifier: -style label directly following the default: or case x: labels. That's not what this question is about. I'm more curious as to whether there is any actual rationale behind prohibiting this kind of

Why can't I “goto default;” or “goto case x;” within a switch selection structure?

醉酒当歌 提交于 2021-02-07 11:22:38
问题 Section 6.8.1 of C11 or C99, or section 3.6.1 of C89 all seem to indicate that default and case x (where x is some constant-expression ) are examples of labeled statements, along-side identifier: -style labels that are suitable for use with goto . I'm aware that I could simply place an identifier: -style label directly following the default: or case x: labels. That's not what this question is about. I'm more curious as to whether there is any actual rationale behind prohibiting this kind of

Why can't I “goto default;” or “goto case x;” within a switch selection structure?

ぐ巨炮叔叔 提交于 2021-02-07 11:22:32
问题 Section 6.8.1 of C11 or C99, or section 3.6.1 of C89 all seem to indicate that default and case x (where x is some constant-expression ) are examples of labeled statements, along-side identifier: -style labels that are suitable for use with goto . I'm aware that I could simply place an identifier: -style label directly following the default: or case x: labels. That's not what this question is about. I'm more curious as to whether there is any actual rationale behind prohibiting this kind of