News for hackers. Stuff that matters.
Re:C Programming Guidelines by hyc_symas on Wednesday September 02, 2015 @01:55AM (#10157638)
"Put one statement conditionals on same line as condition: if (rc < 0) goto fail;"

This is bad advice. A source-level debugger only works in source line numbers; if you ever need to set a breakpoint to find out when an error condition occurs you need to be able to set it on the action statement "goto fail" and not be bothered by the breakpoint tripping every time the if() gets evaluated.

Always separate the conditional from the statement.

Re:C Programming Guidelines by fishanz on Wednesday September 02, 2015 @02:13AM (#10157684)
I totally agre and that immediately popped out at me. When I started coding I would do this to 'save space', until burned by the breakpoint as you point out. Then I started putting it on the next line, indented, until a more seasoned developer told me about the gotchas of not having braces around a 'one-liner'. So now what used to take one line takes 4 lines, but I'm sure it will circumvent a 'goto fail' bug at some point!
Re:C Programming Guidelines by ufo on Wednesday September 02, 2015 @02:50AM (#10157771)
Its only 3 lines if you use the One True Brace Style.
Re:C Programming Guidelines by fishanz on Thursday September 03, 2015 @02:00AM (#10163536)
Well, when I was learning c, Egyptian brackets apparently weren't even a thing. I have co-opted their use in certain places - I think it's a nice way to easily identify a lambda function, but I don't think I would ever use it in pure c. I simply like the way braces line up even if it takes up an extra line .. Kinda like reading HTML, you'd never put an opening tag at the end of a line, right? Anyway, I'm sure this topic has been exhausted a long time ago in a different post.
Re:C Programming Guidelines by btrask on Wednesday September 02, 2015 @06:22PM (#10162297)
Hey Howard, thanks for the feedback. That's a good point that I hadn't really run into (probably depends on personal debugging style). I still think keeping error handlers small is worth it, but I will mention that tradeoff.
Re:C Programming Guidelines by electroly on Thursday September 03, 2015 @11:55AM (#10165641)
Maybe your source-level debugger only works in line numbers. Visual Studio doesn't. It knows that "goto fail" is a separate statement and you can place a breakpoint directly on that, not on the if statement, even though they're on the same line.
Re:C Programming Guidelines by CardenB on Wednesday September 02, 2015 @02:00AM (#10157648)
Plus it just seems like a readability issue in the long run.