Is it possible, using the C/C++ preprocessor, to count lines within a source file, into either a macro or some kind compile-time-available value? E.g. can I replace MAGIC1, MAGIC2 and MAGIC3 in the following, and get the value 4 somehow when using MAGIC3?
MAGIC1 // can be placed wherever you like before the relevant // lines - either right before them, or in global scope etc. foo(); MAGIC2 bar(); MAGIC2 baz(); MAGIC2 quux(); MAGIC2 // ... possibly a bunch of code here; not guaranteed to be in same scope ... MAGIC3 Notes:
- Compiler-specific extensions to the preprocessor's capabilities are acceptable but undesirable.
- If this is possible only with the help of some of C++, as opposed to C, construct, that's also acceptable but undesirable (i.e. I'd like something that would work for C).
- Obviously this can be done by running the source file through some external processor script, but that's not what I'm asking.
__LINE__that represents the current line number__COUNTER__and/orBOOST_PP_COUNTER?int arr[MAGIC4]and get the number of lines in some previously-counted section of my code.