Questions tagged [gcc-pedantic]

The pedantic option to gcc to forces ANSI-compatibility of code.

The -pedantic option of gcc is a stricter version of the related -ansi and -std= options, which specify C standard versions that should be complied to. Though these options disable non-compliant extensions, the -pedantic option goes further. Not only does it disable these extensions, it issues warnings for all instances of code non-compliance that the standard requires a diagnostic for, and rejects more non-compliant code than the other options alone.

There is also the -pedantic-errors option, issuing errors instead of warnings.

However, even this cannot detect or block every instance of ISO C non-compliance.

From the gcc manpage:

**-Wpedantic**
**-pedantic**
Issue all the warnings demanded by strict ISO C and ISO C++;
reject all programs that use forbidden extensions, and some
other programs that do not follow ISO C and ISO C++.  For ISO
C, follows the version of the ISO C standard specified by any
-std option used.

Valid ISO C and ISO C++ programs should compile properly with
or without this option (though a rare few require -ansi or a
-std option specifying the required version of ISO C).
However, without this option, certain GNU extensions and
traditional C and C++ features are supported as well.  With
this option, they are rejected.

-Wpedantic does not cause warning messages for use of the
alternate keywords whose names begin and end with __.
Pedantic warnings are also disabled in the expression that
follows "__extension__".  However, only system header files
should use these escape routes; application programs should
avoid them.

Some users try to use -Wpedantic to check programs for strict
ISO C conformance.  They soon find that it does not do quite
what they want: it finds some non-ISO practices, but not
all---only those for which ISO C requires a diagnostic, and
some others for which diagnostics have been added.

A feature to report any failure to conform to ISO C might be
useful in some instances, but would require considerable
additional work and would be quite different from -Wpedantic.
We don't have plans to support such a feature in the near
future.


Where the standard specified with -std represents a GNU
extended dialect of C, such as gnu90 or gnu99, there is a
corresponding base standard, the version of ISO C on which
the GNU extended dialect is based.  Warnings from -Wpedantic
are given where they are required by the base standard.  (It
does not make sense for such warnings to be given only for
features not in the specified GNU C dialect, since by
definition the GNU dialects of C include all features the
compiler supports with the given option, and there would be
nothing to warn about.)

**-pedantic-errors**
Give an error whenever the base standard (see -Wpedantic)
requires a diagnostic, in some cases where there is undefined
behavior at compile-time and in some other cases that do not
prevent compilation of programs that are valid according to
the standard. This is not equivalent to -Werror=pedantic,
since there are errors enabled by this option and not enabled
by the latter and vice versa.
29 questions
2
votes
1 answer

-Wpedantic wrong type argument to increment after casting

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…
Thüzhen
  • 183
  • 6
2
votes
1 answer

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

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…
kenneth
  • 37
  • 1
  • 1
  • 2
2
votes
1 answer

Function to read a key without waiting for LF

I'm looking throughout the Internet in search of some function that will read a key from keyboard without waiting for LF (like getch() from conio.h). Unfortunately I have to compile it with gcc using switches -ansi and -pedantic, which makes getch()…
Sushi271
  • 544
  • 2
  • 8
  • 22
2
votes
1 answer

static_cast / float / bitset / const weirdness

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…
stefan
  • 10,215
  • 4
  • 49
  • 90
2
votes
2 answers

scope g++ pedantic compile

Is it possible to restict the -pedantic switch for certain files? For example I compile stuff using alsa-lib, which I refer with standard #include however -pedantic panics on this file. I am willing and interested in correcting…
Eric
  • 19,525
  • 19
  • 84
  • 147
1
vote
1 answer

Problem with downloading data - vertices of square

I would like to write a program in which you give two vertices of the square and the program finds the other two. for example: input: 2 3 4 5 output (3,6) (0,5) But I have a problem when it reads data from the program everything works fine int…
Roundstic
  • 21
  • 3
1
vote
1 answer

how to download an unrestricted line from a file using the fread function?

I have a question how to download a line of text from the file without specifying the size of this line? I wouldn't want to use fgets because you have to give the fgets to the characters in advance. I can load the whole file, but not one line.…
Roundstic
  • 21
  • 3
1
vote
1 answer

Forward define struct AND type without any warnings

Our universitie's homework submission system has - instead of focusing on programming skills - set ridiculous and impractical requirements on submissions. To bypass that, I use preprocesor and few other tricks to merge my homework solution into one…
Tomáš Zato
  • 50,171
  • 52
  • 268
  • 778
1
vote
1 answer

Why would certain deprecated classes NOT generate a warning while compiling with g++?

I noticed today that one of my header files was still using an auto_ptr<> template. I am using -std=c++11 to make sure to compile in C++11 and -pedantic and -Werror to detect deprecated usage. So I would imagine that I should have had an error while…
Alexis Wilke
  • 19,179
  • 10
  • 84
  • 156
0
votes
1 answer

C++ g++ -pedantic warning

I am studying Bjarne Stroustrup's book 'Programming Principles and Practice Using C++'. I downloaded his header file from here and used the following compiling command in VSCode on Windows: g++ -Wall -Wextra -Wconversion -pedantic -std=c++17 -g -c…
0
votes
1 answer

Will -Wpedantic do anything when compiling with a non-extension -std?

If I compile my C or C++ code with GCC, using -std=c99 or -std=c++11 or some other proper ISO standard rather than a GNU extension - will -Wpedantic issue more warnings that I would usually get? e.g. With -W, -Wall or -Wall -Wextra?
einpoklum
  • 118,144
  • 57
  • 340
  • 684
0
votes
1 answer

gcc makefile with -Wall -pedantic and -lpthread

I have tried to make a makefile from a template and this is what I've got: CFLAGS = -Wall -pedantic LFLAGS = -lpthread CC = gcc OBJS = bank5.o client2.o PROGRAM = ex2 all: bank client ex2: $(OBJS) $(CC) $(LFLAGS) $(OBJS) -o $(PROGRAM) bank:…
Mari
  • 35
  • 3
0
votes
2 answers

Ansi C and Temporary Files

I need the integer file descriptor from a temporary file to be used in mmap. This need may need to change if there's no simple way to do this while still being standards compliant. I originally got a FILE stream using: FILE *tmpfile(); and then…
Harry
  • 11,298
  • 1
  • 29
  • 43
-2
votes
2 answers

C program crashes when using getchar after allocating memory

I'm making a C program where I have to use -ansi and -pedantic. I want to read the stdin input but when I call getchar() the program crashes. Here is the line that makes the error : while((data = getchar()) != EOF) { When I run it normally it…
1
2