Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • This will work only if my use of the line-count is in the same scope as the counted lines. IIANM. Note I edited my question slightly to emphasize that could be an issue. Commented Jan 8, 2020 at 11:25
  • 1
    @einpoklum A __COUNTER__ based solution has issues too: you better hope your magic macro is the only user of __COUNTER__, at least before you're done with your use of __COUNTER__. The problem basically all comes down to the simple facts that __COUNTER__/__LINE__ are preprocessor features and the preprocessor works in one pass, so you can't backpatch an integer constant expression later based on __COUNTER__/__LINE__. The only way (in C at least) is to avoid the need in the first place, e.g., by using forward array declarations without size (incompletely typed array declarations). Commented Jan 8, 2020 at 11:38
  • 1
    For the record, the \ does not affect __LINE__ - if there is a line break, __LINE__ increases. Example 1, example 2. Commented Jan 8, 2020 at 12:01
  • @MaxLanghof Thanks. Didn't realize that. Fixed. Commented Jan 8, 2020 at 12:11