Do I need -pedantic flag from GCC with C11?

Viewed 5505

I'm currently running Linux Mint on my Machine with GCC-5.3 because C11 is included default.

I started learning C for myself just for fun and at that time the GCC version was 4.8 if I remember right.

Any way if one use GCC-4.8 with -pedantic flag on the following program:

#include <stdio.h>
#include <string.h>

int main(void){
    char *arr = "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
    size_t length = strlen(arr);
    printf("Length of Arr = %zu\n",length);
}

At the compile time one gets the following warnings:

program.c: In function ‘main’:
program.c:5:5: warning: string length ‘510’ is greater than the length ‘509’ ISO C90 compilers are required to support [-Woverlength-strings]
     char *arr = "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
     ^
program.c:7:5: warning: ISO C90 does not support the ‘z’ gnu_printf length modifier [-Wformat=]
     printf("Length of Arr = %zu\n",length);
     ^
program.c:8:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^

If we see this part of the warning:

warning: string length ‘510’ is greater than the length ‘509’ ISO C90 compilers are required to support [-Woverlength-strings]

Is somehow clear that -pedantic flag is a problem here so I decided to not use it and avoid it like avoid -ansi too because of the new (last) standard C11.

Now if I compile the same program with GCC-5.3:

gcc-5 -Wall -pedantic program.c -o program

The program compiles fine with NO WARNINGS.

Now based on the following Question Return void type in C and C++ if I try to compile the following program:

#include <stdio.h>
#include <string.h>

void f(void);
void f2(void);

int main(void){
    f();
}


void f(void){
}

void f2(void){
    return f();
}

With the following:

gcc-5 -Wall -pedantic program.c -o program

I get:

program.c: In function ‘f2’:
program.c:16:16: warning: ISO C forbids ‘return’ with expression, in function returning void [-Wpedantic]
         return f();
                ^

But compiles fine without the ´-pedantic` flag. This is a confusion for me.

Which shows me that somehow I do need the -pedantic flag, but I'm not sore.

So, my Question is, do we need to make use of -pedantic anymore with C11?

6 Answers
Related