Hacker News new | past | comments | ask | show | jobs | submit login

Isn't `#pragma once` helpful for avoiding reparsing headers?



`#pragma once` is to prevent a header from being reparsed repeatedly for the same translation unit when ten different headers all include a common one transitively.

it replaces the prior pattern of including code predicated on a unique definition defined only within that same block to avoid double parsing.

    /* if it isn't unique, you're going to have a bad time */
    #ifndef SOME_HOPEFULLY_UNIQUE_DEFINITION
    #define SOME_HOPEFULLY_UNIQUE_DEFINITION
    
    ...code...
    
    #endif /* SOME_HOPEFULLY_UNIQUE_DEFINITION */
This, however, doesn't stop those same headers from needing to be reread and reparsed and reread and reparsed for every single cpp file in the project.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: