skip to main content
10.1145/3361149.3361151acmotherconferencesArticle/Chapter ViewAbstractPublication PageseuroplopConference Proceedingsconference-collections
research-article

Patterns to escape the #ifdef hell

Published:03 July 2019Publication History

ABSTRACT

There are many things one can do wrong when using the C pre-processor's #ifdef statements. Such statements are often used to distinguish between hardware variants or operating system variants in the C code and when not used carefully, the C code easily becomes a mess of #ifdef cascades. This paper addresses this issue and provides best practices in form of patterns on how to organize variants in C code and on how to get rid of #ifdef statements.

References

  1. Flemming Bunzel. 2013. Hardware-abstraction of an open source real-time Ethernet stack - Design, realisation and evaluation.Google ScholarGoogle Scholar
  2. Brian Hook. 2005. Write Portable Code: An Introduction to Developing Software for Multiple Platforms. No Starch Press.Google ScholarGoogle Scholar
  3. Didier Malenfant. 2000. Writing Portable Code. In GDC.Google ScholarGoogle Scholar
  4. Robert C. Martin. 2008. Clean Code: A Handbook of Agile Software Craftsmanship. Prentice Hall PTR.Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. Christopher Preschern. 2015. Idioms for Error Handling in C. In Proceedings of the 20th European Conference on Pattern Languages of Programming (EuroPLoP).Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. Christopher Preschern. 2016. API Patterns in C. In Proceedings of the 21st European Conference on Pattern Languages of Programming (EuroPLoP).Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. Christopher Preschern. 2017. Patterns for C Iterator Interfaces. In Proceedings of the 22nd European Conference on Pattern Languages of Programming (EuroPLoP).Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. Christopher Preschern. 2018. C Patterns on Objects and their Lifetime. In Proceedings of the 23rd European Conference on Pattern Languages of Programming (EuroPLoP).Google ScholarGoogle Scholar
  9. Christopher Preschern. 2018. Patterns for Returning Data from C Functions. In Proceedings of the 23rd European Conference on Pattern Languages of Programming (EuroPLoP).Google ScholarGoogle Scholar
  10. Christopher Preschern. 2019. Patterns for Returning Error Information in C. In Proceedings of the 24th European Conference on Pattern Languages of Programming (EuroPLoP).Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. Henry Spencer and Geoff Collyer. 1992. #ifdef Considered Harmful, or Portability Experience With C News. In Proceedings of the 1992 USENIX Conference.Google ScholarGoogle Scholar

Index Terms

  1. Patterns to escape the #ifdef hell

      Recommendations

      Comments

      Login options

      Check if you have access through your login credentials or your institution to get full access on this article.

      Sign in
      • Published in

        cover image ACM Other conferences
        EuroPLop '19: Proceedings of the 24th European Conference on Pattern Languages of Programs
        July 2019
        431 pages
        ISBN:9781450362061
        DOI:10.1145/3361149

        Copyright © 2019 ACM

        Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than the author(s) must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected].

        Publisher

        Association for Computing Machinery

        New York, NY, United States

        Publication History

        • Published: 3 July 2019

        Permissions

        Request permissions about this article.

        Request Permissions

        Check for updates

        Qualifiers

        • research-article

        Acceptance Rates

        Overall Acceptance Rate216of354submissions,61%

      PDF Format

      View or Download as a PDF file.

      PDF

      eReader

      View online with eReader.

      eReader