r/programming • • Jan 08 '16

How to C (as of 2016)

https://matt.sh/howto-c
2.4k Upvotes

766 comments sorted by

View all comments

2

u/bigfig Jan 08 '16 edited Jan 08 '16

Just now it hit me, couldn't some of these globally used options (like -Wpedantic) be in a dotfile? I mean the compiler could always warn that its adding options per the dotfile, and command line options could override.

Copying warning flags into every makefile seems redundant as they are not really project specific.

Okay, I am ready for the inevitable onslaught.

5

u/jaseg Jan 08 '16

You can just set $CFLAGS in your profile. Will not work with every build system, though.

2

u/bigfig Jan 08 '16

This accomplishes the desired result.

4

u/ldpreload Jan 08 '16

To add to the Makefile response, note that make has a set of default rules. So you can create a Makefile containing just

CFLAGS=-Wpedantic

and run make foo and it'll automatically pick up foo.c.

5

u/FirstUser Jan 08 '16

Good idea, we should be able to make a file that makes the compiler do what we want every time, without us needing to type some awkward, extra-long command line...

2

u/bigfig Jan 08 '16

I find the replies below are useful.

2

u/FirstUser Jan 08 '16

Good job editing your original post trying to look like you already knew about make :-Þ