c99

rint() issue after creating VS Project using CMake

孤者浪人 提交于 2019-12-04 06:36:31
问题 I'm having an issue compiling code - specifically METIS - Serial Graph Partitioning and Fill-reducing Matrix Ordering. I've successfully managed to make Visual Studio 2013 Project out of the source files two ways: using CMake GUI (version 3.4.3) and using Command Line. However, in both cases when I try to build the created project in Visual Studio, I'm getting an error: Error C2059: syntax error : '(' on line _CRTIMP double __cdecl rint(_In_ double _X); where _CRTIMP is defined this way:

Is it safe to cast a heap allocated pointer to a pointer to a VLA?

倾然丶 夕夏残阳落幕 提交于 2019-12-04 06:26:12
If I've got a pointer to some heap allocated space that represents a typical row-major two dimensional array, is it safe to cast this pointer to an equivalent pointer to a VLA for convenient sub-scripting? Example: // // Assuming 'm' was allocated and initialized something like: // // int *matrix = malloc(sizeof(*matrix) * rows * cols); // // for (int r = 0; r < rows; r++) { // for (int c = 0; c < cols; c++) { // matrix[r * cols + c] = some_value; // } // } // // Is it safe for this function to cast 'm' to a pointer to a VLA? // void print_matrix(int *m, int rows, int cols) { int (*mp)[cols] =

Why are structs not allowed in equality expressions in C? [duplicate]

一笑奈何 提交于 2019-12-04 06:02:09
This question already has answers here : Closed 2 years ago . Why doesn't C provide struct comparison? (5 answers) The unavailability of structs as comparison operands is one of the more obvious things in C that don't make too much sense (to me). structs can be passed by value and copied via assignments but == is not specified for them. Below are the relevant parts of the C11 standard (draft) that define the constraints of the equality operators ( == and != ) and the simple assignment operator ( = ). Note the lack of structures and unions in the constraints of equality operators. (Apart from

Floats being Inexact

坚强是说给别人听的谎言 提交于 2019-12-04 05:16:18
问题 I am puzzled. I have no explanation to why this test passes when using the double data type but fails when using the float data type. Consider the following snippet of code. float total = 0.00; for ( int i = 0; i < 100; i++ ) total += 0.01; One would anticipate total to be 1.00, however it is equal to 0.99. Why is this the case? I compiled with both GCC and clang, both compilers have the same result. 回答1: The value for 0.01 in decimal is expressed as the series: a1*(1/2) + a2*(1/2)^2 + a3*(1

Struct vs string literals? Read only vs read-write? [duplicate]

假如想象 提交于 2019-12-04 05:04:49
This question already has answers here : Closed 12 months ago . Why are compound literals in C modifiable (1 answer) Why do I get a segmentation fault when writing to a string initialized with “char *s” but not “char s[]”? (17 answers) Does the C99 standard permit writing to compound literals (structs)? It seems it doesn't provide writing to literal strings. I ask about this because it says in C Programming: A Modern Approach, 2nd Edition on Page 406. Q. Allowing a pointer to a compound literal would seem to make it possible to modify the literal. Is that the case? A. Yes. Compound literals

Where can I find a table of all the characters for every C99 Character Set?

风格不统一 提交于 2019-12-04 03:54:34
I'm looking for a table (or a way to generate one) for every character in each of the following C Character Sets: Basic Character Set Basic Execution Character Set Basic Source Character Set Execution Character Set Extended Character Set Source Character Set C99 mentions all six of these under section 5.2.1 . However, I've found it extremely cryptic to read and lacking in detail. The only character sets that it clearly defines is the Basic Execution Character Set and the Basic Source Character Set : 52 upper- and lower-case letters in the Latin alphabet: A B C D E F G H I J K L M N O P Q R S T

implicit int and implicit declaration of functions with gcc compiler

末鹿安然 提交于 2019-12-04 03:49:59
问题 I read in the c99 Standard: -remove implicit function declaration, -remove implicit int. But when I try to compile this code with gcc compiler in c99 mode using -pedantic main(void){ f(3); return 0; } int f(int a){ .... } I expect 2 errors, but I just receive 2 warnings: -warning: return type defaults to ‘int’ -warning: implicit declaration of function ‘f’. Shouldn't them be errors in c99? http://gcc.gnu.org/c99status.html In both situations there's written "done". Thanks. 回答1: The C standard

Variable Length Array

拜拜、爱过 提交于 2019-12-04 03:42:57
I would like to know how a variable length array is managed (what extra variables or data structures are kept on the stack in order to have variable length arrays). Thanks a lot. It's just a dynamically sized array (implementation-dependent, but most commonly on the stack). It's pretty much like alloca in the old days, with the exception that sizeof will return the actual size of the array, which implies that the size of the array must also be stored somewhere (implementation-dependent as well, but probably on the stack too). The size of variable length arrays is determined on run-time,

Why aren't fixed-point types included in C99?

﹥>﹥吖頭↗ 提交于 2019-12-04 03:23:30
Thankfully, the complex type modifier was introduced into C99 standard. What I don't understand is why it was decided to omit support for fixed point arithmetic (specifically, support fractional types like 1.15 {signed} or 0.32 {unsigned}) where these types are so fundamental to DSP programming? Does GCC support these through an extension? It's been discussed/proposed (e.g., in N938 , N953 ) but those papers have only proposed it as extensions, not additions to the main standard. Those seem to have led to its inclusion in N1169 , which is a draft of TR 18037 ("Extensions to support embedded

A bug in GCC implementation of bit-fields

隐身守侯 提交于 2019-12-04 03:02:45
Working in C11, the following struct: struct S { unsigned a : 4; _Bool b : 1; }; Gets layed out by GCC as an unsigned (4 bytes) of which 4 bits are used, followed by a _Bool (4 bytes) of which 1 bit is used, for a total size of 8 bytes. Note that C99 and C11 specifically permit _Bool as a bit-field member. The C11 standard (and probably C99 too) also states under §6.7.2.1 'Structure and union specifiers' ¶11 that: An implementation may allocate any addressable storage unit large enough to hold a bit-field. If enough space remains, a bit-field that immediately follows another bit-field in a