|
|
Subscribe / Log in / New account

Switch-case fall-through dangerous?

Switch-case fall-through dangerous?

Posted Aug 31, 2018 12:26 UTC (Fri) by dezgeg (subscriber, #92243)
In reply to: Switch-case fall-through dangerous? by karkhaz
Parent article: C considered dangerous

The compiler switch already exists for GCC 7, it is -Wimplicit-fallthrough. And it knows to how to parse a comment like /* fall through */ as described.

The usage of comments as "keywords" to guide static analysis is a pretty old thing. The convention dates back at least to the original 'lint' tool for UNIX from 1978! See: http://files.cnblogs.com/files/bangerlee/10.1.1.56.1841.pdf


to post comments

Switch-case fall-through dangerous?

Posted Aug 31, 2018 12:34 UTC (Fri) by karkhaz (subscriber, #99844) [Link] (1 responses)

Thanks for this information! Though the use of comments seems ugly, like it would complicate the design of the compiler...compilers should be free to lex the comments out without considering the possibility that they contain interpretable information. On the other hand, I suppose comments are better than nonstandard keywords, which would tie you to using only compilers that understand them.

Switch-case fall-through dangerous?

Posted Aug 31, 2018 19:00 UTC (Fri) by khim (subscriber, #9252) [Link]

Well, you could use C++, where it's standard keyword instead.


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