3 ms·
Isn't `#pragma once` helpful for avoiding reparsing headers?
by zerr 2y ago
Isn't `#pragma once` helpful for avoiding reparsing headers?
- knome 2y ago`#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.