News for hackers. Stuff that matters.
Re:Signs that you're a bad programmer by torpor on Friday August 07, 2009 @05:09AM (#747325)
How to avoid (if you're a C programmer) writing utterly terrible code - always include these WARNINGS in your build step:

WARNINGS := -Wall -W -Wunused-parameter -Wmissing-declarations

WARNINGS += -Wstrict-prototypes -Wmissing-prototypes -Wsign-compare

WARNINGS += -Wconversion -Wshadow -Wcast-align -Wparentheses

WARNINGS += -Wsequence-point -Wdeclaration-after-statement -Wundef

WARNINGS += -Wpointer-arith -Wnested-externs -Wredundant-decls

WARNINGS += -Werror -Wdisabled-optimization -pedantic

CFLAGS += $(WARNINGS)

Note: -pedantic is pretty good if you really wanna learn how to write code that will work properly.

Also: Treating Warnings as Errors is a good thing. You'll learn a lot, and the most important thing will be: handle all warnings. Do not release code until it builds clean.

Re:Signs that you're a bad programmer by sfk on Friday August 07, 2009 @07:35AM (#747414)
Good advice, but compilers often issue warnings like "x may be used uninitialized" even when it cannot happen.
Re:Signs that you're a bad programmer by torpor on Friday August 07, 2009 @07:58AM (#747435)
Erm, wut? Not really. If there is a warning, its there for a reason. Fix that.
Re:Signs that you're a bad programmer by sfk on Friday August 07, 2009 @10:46AM (#747640)
As everyone who has written a C program of sufficient complexity knows, these warnings are not always correct. Google for "spurious warnings uninitialized", e.g:

http://kerneltrap.org/node/6591

An unrelated example where gcc (and icc) emit needless warnings about integer types is this:

  int x = foo();
  unsigned y = (x == 0);

Don't get me wrong, I'm in favor of cranking up the warning levels, but there is a reason why not everything is included in -Wall (yes, "uninitialized" is included, I know).
Re:Signs that you're a bad programmer by torpor on Tuesday August 11, 2009 @07:51AM (#755020)
As a professional C coder for 20+ years, with well over a million lines of code under my belt, I can tell you that anyone that is ignoring warnings because of a buggy compiler is using the wrong compiler and should fix that immediately.

I work on SIL-4 rated systems for life-protection applications. Absolutely ZERO TOLERANCE for warnings is a requirement in this job, and every single time it has been addressed, the warning gave us a clue how to fix something. Whether it was the code that needed fixing, or the compiler - either way, the alert is there. Ignore at your own peril.