Live data from Hacker News

What Are Your GCC Flags?

blog.httrack.com

31–40 of 117 posts

Re: What Are Your GCC Flags?

#31
post #24
post #19

Earlier quoted context omitted.

Our experience is that it is actually an excellent sanitary decision. We are using multiple builders with fixed GCC releases (for RHEL5, RHEL6 etc. flavors), and yes it means fixing additional warnings when we have to introduce a new architecture. But I can not count the number of serious issues we avoided by spotting and investigating warnings.

That's fine and dandy. It's not fine when it's an open source project from three years and four compiler versions ago that you want to compile, and find -Werror on every line invocation in a Makefile. What you build with in-house for development/test-farms is not what you should ship as default to users of your project.

find -Werror on every line invocation in a Makefile

If it's on every line and not kept in one place in $(CFLAGS), you have bigger problems.

Re: What Are Your GCC Flags?

#32

Earlier quoted context omitted.

-Westsieeeede

-WetPsyyyyyyy

Just for reference, the parent is a reference to a lyric from Psy's (the Korean artist responsible for Gangnam Style) song 'Gentleman', wherein he parodies the expression 'Westsiiiiiide' (not that this necessarily makes it any funnier).

Re: What Are Your GCC Flags?

#34
post #17

This is probably an unpopular opinion, but: -Werror is fine on your dev machine, but is a very bad idea in the official build system, notably if you do it for a library that you want people to use. As soon as you want to compile with various compilers, systems, use cross-compilation and other funny things that makes it portable, you're going to have a bad time. New compilers will make new warnings, old compilers will…

I experienced issues with this flag being used by an open source library in autotools (specifically the AM_INIT_AUTOMAKE option in the configure.ac file). The actual C code also used -Werror, and compiled perfectly, but "./configure" wouldn't complete because of minor "this is a GNU extension" and similar errors during automake.

Not being an autotools guru this was incredibly frustrating. I had no idea why the damn thing wasn't working until I noticed "warnings are treated as errors".

Please don't use -Werror in any context if your project is open source.

Re: What Are Your GCC Flags?

#36
I tend to go with:

  gcc -c -Wall -Werror -std=c99 -pedantic -O3
I use -std=c99 because I use these two features of C:

1. Mixed declarations and code, e.g.

  double x = 4.8 * 5.3;
  printf("x = %.15g\n", x);
  double y = 8.7 * x;
  printf("y = %.15g\n", y);
2. Flexible array members, e.g. for my safe string operations:

  struct str 
      {       
      long len;
      char data[];
      };
If I were to use -ansi (same as -std=c89), instead of -std=c99, then -pedantic would give me these errors:

  error: ISO C90 forbids mixed declarations and code [-Werror=edantic]

  error: ISO C90 does not support flexible array members [-Werror=edantic]
(By the way, I have no idea why the error message omits the "p" from pedantic there. That doesn't smell right. I hope the gcc people fix that.)

I use -O3 for optimization, and I chose level 3 because that enables -finline-functions. I typically avoid macros, even for simple one-liners like this:

  /* Increment the reference count. */
  void hold(value f)
      {
      f->N++;
      }
With -finline-functions enabled (via -O3), I can see that function being expanded inline, by examining the assembly output of gcc -S -O3.

Re: What Are Your GCC Flags?

#38
post #36

I tend to go with: gcc -c -Wall -Werror -std=c99 -pedantic -O3 I use -std=c99 because I use these two features of C: 1. Mixed declarations and code, e.g. double x = 4.8 * 5.3; printf("x = %.15g\n", x); double y = 8.7 * x; printf("y = %.15g\n", y); 2. Flexible array members, e.g. for my safe string operations: struct str { long len; char data[]; }; If I were to use -ansi (same as -std=c89), instead of -std=c99, then -…

Why don't you use -O2 -finline-functions then?

Re: What Are Your GCC Flags?

#39
post #12

Very surprising to not see the -std option to actually clarify which language standard is being used. Perhaps that isn't as important in C++ as it is in C.

Agreed, see my post above about -std=c99.

Re: What Are Your GCC Flags?

#40
post #38
post #36

I tend to go with: gcc -c -Wall -Werror -std=c99 -pedantic -O3 I use -std=c99 because I use these two features of C: 1. Mixed declarations and code, e.g. double x = 4.8 * 5.3; printf("x = %.15g\n", x); double y = 8.7 * x; printf("y = %.15g\n", y); 2. Flexible array members, e.g. for my safe string operations: struct str { long len; char data[]; }; If I were to use -ansi (same as -std=c89), instead of -std=c99, then -…

Why don't you use -O2 -finline-functions then?

Good question. I go with -O3 because it does even more optimizations, but to be quite candid I really don't know what impact -fpredictive-commoning, -ftree-vectorize, and others have on my resulting machine code, if any.

I did a quick experiment, compiling one C file with -O2 -finline-functions and another with -O3, using the -S flag so I could see the assembler output.

The only difference I saw was this:

  .comm	free_list,8,8
Versus this:

  .comm	free_list,8,16
Who knows. I guess I'm really using -O3 because "3 is more than 2" -- in other words, "Ours goes to 11!" :)
Post reply on HN