C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Preprocessor macro __COUNTER__

From: Lénárd Szolnoki <cpp_at_[hidden]>
Date: Tue, 16 Aug 2022 15:26:09 +0100
It is an ODR-violation footgun when used in header files.

On 16 August 2022 12:53:00 BST, Frederick Virchanza Gotham via Std-Proposals <std-proposals_at_[hidden]> wrote:
>Every C++ compiler suite I'm aware of supports the preprocessor macro
>__COUNTER__.
>
>So if I do the following:
>
>#include <iostream>
>
>auto main(void) -> int
>{
> std::cout << __COUNTER__ << std::endl;
> std::cout << __COUNTER__ << std::endl;
> std::cout << __COUNTER__ << std::endl;
> std::cout << __COUNTER__ << std::endl;
>}
>
>Then it prints:
>0
>1
>2
>3
>
>I see that in C++20 we have "std::source_location" which can probably
>take the place of __FILE__, __LINE__, and maybe also __COUNTER__ in
>some scenarios, but I still think __COUNTER__ should be standard C++.
>--
>Std-Proposals mailing list
>Std-Proposals_at_[hidden]
>https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2022-08-16 14:26:15