User: Password:
|
|
Subscribe / Log in / New account

Reitter: Answering the question: "How do I develop an app for GNOME?"

Reitter: Answering the question: "How do I develop an app for GNOME?"

Posted Feb 6, 2013 21:45 UTC (Wed) by zlynx (subscriber, #2285)
In reply to: Reitter: Answering the question: "How do I develop an app for GNOME?" by HelloWorld
Parent article: Reitter: Answering the question: "How do I develop an app for GNOME?"

And for C/C++ there is usually a compiler option to warn/error about ignored function return values. This is incredibly useful and should be required.


(Log in to post comments)

Reitter: Answering the question: "How do I develop an app for GNOME?"

Posted Feb 6, 2013 21:58 UTC (Wed) by mpr22 (subscriber, #60784) [Link]

Unfortunately, C code that meticulously collects the return value of everything that can fail essentially-harmlessly is a real pain in the neck to read, because it's salted either with cast-to-void or with piles of pointless error-checking logic. (I hate reading C code where some coding-standards martinet has insisted that all printf() calls must be cast to void.)

Reitter: Answering the question: "How do I develop an app for GNOME?"

Posted Feb 8, 2013 14:51 UTC (Fri) by jwakely (guest, #60262) [Link]

> And for C/C++ there is usually a compiler option to warn/error about ignored function return values.

What's GCC's option for that?

You can use __attribute__((warn_unused_result)) but putting that on every function returning non-void is hardly practical, let alone portable.

Reitter: Answering the question: "How do I develop an app for GNOME?"

Posted Feb 12, 2013 19:51 UTC (Tue) by mgedmin (subscriber, #34497) [Link]

-Wno-unused-result exists, according to the gcc(1) manual page.

Reitter: Answering the question: "How do I develop an app for GNOME?"

Posted Feb 12, 2013 20:21 UTC (Tue) by nybble41 (subscriber, #55106) [Link]

The -Wno-unused-result option does exactly the opposite of what is wanted: it turns off the warning which would otherwise be issued for functions which have been tagged with __attribute__((warn_unused_result)). You still have to tag specific functions whose results should not be ignored. There does not appear to be an option to enable the warning for all non-void functions by default.

Reitter: Answering the question: "How do I develop an app for GNOME?"

Posted Feb 12, 2013 21:03 UTC (Tue) by mpr22 (subscriber, #60784) [Link]

Enabling the warning for all non-void functions by default leads to code being liberally salted with futile error-checking and/or casts-to-void.

Reitter: Answering the question: "How do I develop an app for GNOME?"

Posted Feb 12, 2013 22:56 UTC (Tue) by Cyberax (✭ supporter ✭, #52523) [Link]

Futile?

Nope. Apart from maybe printf() - most of the error checking is necessary for secure code.

It just shows that exception handling is really much better than return codes when you want something that's reliable _and_ easy to read.

Reitter: Answering the question: "How do I develop an app for GNOME?"

Posted Feb 12, 2013 21:04 UTC (Tue) by zlynx (subscriber, #2285) [Link]

You are right that there is no global option in GCC. I was thinking of the per-function attribute.

Warnings about unused results are also common in code analysers like Splint and others.


Copyright © 2017, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds