tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: __dead functions




On 18-Jul-08, at 10:51 AM, Alexander Shishkin wrote:

Or maybe an assertion can be placed right before __NOTREACHED?

An assertion is a run-time failure, not a compile time failure.

Even if it were true that this function were never to return, I'm still not sure an assertion would be the best thing. That would depend entirely on the context.


/*
+ * Explicitly specify that a certain point in the codepath should not
+ * be reached and indicate so to gcc.
+ */
+#if __GNUC_PREREQ__(4, 3)
+#define __NOTREACHED for (;;) continue
+#else
+#define __NOTREACHED
+#endif

I think inventing extra redundant identifiers like this one, even if prefixed by "__" is unnecessary.

Indeed gcc doesn't understand a NOTREACHED comment, that's a lint directive of course and it seems, unfortunately, that lint has fallen out of favour in NetBSD. However you can tell gcc a function doesn't return with "__attribute__ ((noreturn))" attached to a prototype.

<sys/cdefs.h> already defines an empty "__attribute__" macro for non- GCC compilers.

--
                                        Greg A. Woods; Planix, Inc.
                                        <woods%planix.ca@localhost>



Home | Main Index | Thread Index | Old Index