c99

Declaring anonymous struct in for loop, clang fails to compile

∥☆過路亽.° 提交于 2020-01-14 07:53:13
问题 Code declaring anonymous structs in a for loop worked fine in gcc with -std=c99/gnu99 for (struct {int foo; int bar;} i = {0}; i.foo < 10; i.foo++); However when I switch to clang instead I got the error: error: declaration of non-local variable in 'for' loop Why is this an error? Why would it allow some types (e.g. "int") but not others (e.g. struct {int foo;}) ? This seems inconsistent. Does clang fail to implement c99 correctly or is that code invalid c99 and gcc just happens to support it

Is this use of the Effective Type rule strictly conforming?

夙愿已清 提交于 2020-01-13 19:12:22
问题 The Effective Type rule in C99 and C11 provides that storage with no declared type may be written with any type and, that storing a value of a non-character type will set the Effective Type of the storage accordingly. Setting aside the fact that INT_MAX might be less than 123456789, would the following code's use of the Effective Type rule be strictly conforming? #include <stdlib.h> #include <stdio.h> /* Performs some calculations using using int, then float, then int. If both results are

Does gcc(windows + MinGW) defines SCNd8, SCNu8 in inttypes.h?

我的梦境 提交于 2020-01-13 10:17:12
问题 #include <stdio.h> #include <inttypes.h> int main(void) { int8_t int8; int16_t int16; int32_t int32; int64_t int64; uint8_t uint8; uint16_t uint16; uint32_t uint32; uint64_t uint64; scanf("%"SCNd8"%"SCNd16"%"SCNd32"%"SCNd64"%"SCNu8"%"SCNu16"%"SCNu32"%"SCNu64, &int8, &int16, &int32, &int64, &uint8, &uint16, &uint32, &uint64); printf("%"PRId8"\n%"PRId16"\n%"PRId32"\n%"PRId64"\n%"PRIu8"\n%"PRIu16"\n%"PRIu32"\n%"PRIu64"\n", int8, int16, int32, int64, uint8, uint16, uint32, uint64); return 0; } I

Using-block in C

大憨熊 提交于 2020-01-13 01:29:30
问题 When having arrays of structures I often miss the With-block approach I got used to in VB6 (similar to the Using-block in C#). For example, many of my code looks now like: Data.attribute[i].ref->value[i]->member.val1 = 0; Data.attribute[i].ref->value[i]->member.val2 = 2; Data.attribute[i].ref->value[i]->member.val3 = 3; While I liked to do something like: with Data.attribute[i].ref->value[i]->member { .val1 = 3; .val2 = 2; .val3 = 3; } I know I can create a temporary variabele, but is

Function overloading in C using GCC - functions with mutiple arguments

耗尽温柔 提交于 2020-01-05 11:14:10
问题 In a previous question I found a way to overload functions in C99 when each function only took a single argument. See the answers in: Function overloading in C using GCC - compiler warnings for details. Now that I've found a way to do it with single argument functions I'm wondering how this can be done for functions that take multiple arguments. I assume it will have something to do with __VA_ARGS__ and using ... but I can't seem to find anything that works or even wants to compile. This will

Where does string-literal begin and end?

六眼飞鱼酱① 提交于 2020-01-05 07:51:39
问题 The C99 standard says the implementation limit for characters of a string literal is 4095(?). But where exactly does a literal end and begin? printf( "First part" "second part!\r\n" ); Would this be a single string literal? Or are this 2 string literals? 回答1: N1256 5.2.4.1 says: 4095 characters in a character string literal or wide string literal (after concatenation) The "after concatenation" refers to the concatenation of adjacent string literals that occurs in translation phase 6 (5.1.1.2)

Blank initialising an array of structs in C99

六月ゝ 毕业季﹏ 提交于 2020-01-05 05:34:05
问题 This seems like a hole in my knowledge. As far as I am aware, in C99 if you initialise a single element of a struct and no others, the others are zero initialised. Does the following code zero initialise all the members of a struct though? typedef struct { int foo; int bar; char* foos; double dar; } some_struct_t; some_struct_t mystructs[100] = {}; Update: There are some comments indicating that this syntax is an extension. If that is the case, is there any way of doing this that is pure C99

C99 equivalent to MATLAB “filter”?

我是研究僧i 提交于 2020-01-05 04:28:11
问题 Why do the MATLAB and C versions produce different results? MATLAB: [B_coeffs, A_coeffs ] = butter(4, 100/(16000/2), 'high'); state = zeros( 4, 1 ); input = zeros( 64,1 ); for i=1:64 input(i)=i; end [filtered_output, state] = filter( B_coeffs, A_coeffs, input, state ); C: int main(...) { for(int test=0; test<64;test++) Xin[test]=test+1; ... high_pass_filter_init(...) high_pass_filter_do(...) } // Do the filtering void high_pass_filter_do( t_high_pass_filter* hpf, float *Xin, float *Yout ) {

Is it possible to create custom-width integers in C?

元气小坏坏 提交于 2020-01-04 18:30:50
问题 The C standard and C compilers come with fixed width integer types, such as uint8_t , int16_t , etc. Is there a way of defining a 128-bit integer in C that would be useable in code using the same semantics as the existing fixed-width integers? 回答1: You'll need something like GMP: http://gmplib.org/ You won't get the "exact" semantics. 回答2: Assuming you're programming a 64-bit machine, you could define a uint128_t type as a struct of two uint64_t s and implement just the arithmetic operators

Is it possible to create custom-width integers in C?

戏子无情 提交于 2020-01-04 18:30:11
问题 The C standard and C compilers come with fixed width integer types, such as uint8_t , int16_t , etc. Is there a way of defining a 128-bit integer in C that would be useable in code using the same semantics as the existing fixed-width integers? 回答1: You'll need something like GMP: http://gmplib.org/ You won't get the "exact" semantics. 回答2: Assuming you're programming a 64-bit machine, you could define a uint128_t type as a struct of two uint64_t s and implement just the arithmetic operators