Skip to content

Instantly share code, notes, and snippets.

@vlasovskikh
Created February 4, 2011 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vlasovskikh/811137 to your computer and use it in GitHub Desktop.
Save vlasovskikh/811137 to your computer and use it in GitHub Desktop.
Funny GCC Warning for FP Programmers

Funny GCC Warning for FP Programmers

(via zakharov)

Consider the following program:

$ cat > tmp.c << EOF
> struct S {
>     int x;
>     int y;
> };
> 
> int f(int x) {
>     struct S s = {x, 42};
>     s.y;
>     return x;
> }
> EOF

Notice the s.y; statement.

Now try to compile the code with GCC warnings enabled:

$ gcc -c -std=c99 -Wall -Wextra -pedantic tmp.c
tmp.c: In function 'f':
tmp.c:8:5: warning: statement with no effect
@vlasovskikh
Copy link
Author

This example could be run as a Cram test:

$ cram --indent 4 README.md
.
# Ran 1 tests, 0 skipped, 0 failed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment