gcc-pedantic

ISO C90 forbids mixed declarations and code because of arrays. How do I fix this?

限于喜欢 提交于 2019-12-24 13:47:35
问题 I tried compiling it using -gcc and it worked as intended but when added with -pedantic , it won't compile. I'm still quite a beginner in programming and it is the first time I encountered this problem so it is quite a problem to me. Here is the code that is causing the error: char *exercise[5]={"swimming", "running", "brisk walking", "weight lifting", "zumba"}; I'd appreciate it if you would explain what the solution is instead of just the fixed code because I want to learn. 回答1: This has

How to traverse an array parameter as void pointer

六月ゝ 毕业季﹏ 提交于 2019-12-23 17:47:19
问题 I have similar "generic" procedure like qsort, which has a void pointer (pointing at an array) and also a function pointer parameter. This function should work on any type of array. Example: void do_something(void * array, int count, int size, void (*test)(const void*)){ int i; for(i=0; i<count; i++){ test(array + (index * size)); } } This however gives me the following warning (gcc test.c -pedantic-errors): error: pointer of type ‘void *’ used in arithmetic [-Wpedantic] And after some

-Wpedantic wrong type argument to increment after casting

我与影子孤独终老i 提交于 2019-12-11 03:59:39
问题 I have a code like while (n--) { *((char*)dest++) = *((char*)src++); } where dest and src are void pointers and n a size. The goal is to re-implement a memcpy function. When compiling this code with gcc, everything works great, but when I add the -Wpedantic flag I have four warnings "wrong type argument to increment". Google tells me that it happens when trying to use arithmetic on void pointers, because gcc treats void type as being a 1 byte type in this case, but legacy compilers shoud not.

static_cast / float / bitset / const weirdness

依然范特西╮ 提交于 2019-12-08 01:57:18
问题 Just a few hours ago, the following question came up: Variable cannot appear in a constant-expression Luckily for the OP, the answer provided did solve his problem, but I cannot reproduce the solution. I've attempted to simplify the code even more and I am now stuck with the following: #include <bitset> int main () { const size_t length_1 = static_cast<const size_t>(1.0f); std::bitset<length_1> bits_1; const size_t length_2 = static_cast<const size_t>(1.0f / 1.0f); std::bitset<length_2> bits

static_cast / float / bitset / const weirdness

你离开我真会死。 提交于 2019-12-06 10:57:40
Just a few hours ago, the following question came up: Variable cannot appear in a constant-expression Luckily for the OP, the answer provided did solve his problem, but I cannot reproduce the solution. I've attempted to simplify the code even more and I am now stuck with the following: #include <bitset> int main () { const size_t length_1 = static_cast<const size_t>(1.0f); std::bitset<length_1> bits_1; const size_t length_2 = static_cast<const size_t>(1.0f / 1.0f); std::bitset<length_2> bits_2; } If compiled with -pedantic , the first example is accepted by the compiler, but the one with a