More Intuitive Syntax for Manifest (enum) Constants
Peter C
peterc at gmail.com
Sat Nov 22 09:01:49 UTC 2025
On Friday, 21 November 2025 at 11:20:51 UTC, Per Nordlöw wrote:
> On Friday, 21 November 2025 at 11:20:08 UTC, Per Nordlöw wrote:
>> is more intuitive and recognizable than
>>
>> ```d
>> macro N = 42;
>> ```
>
> Should be
>
> ```d
> enum N = 42;
> ```
If you want something that is intuitive and instantly
recognizable (i.e. no keyword overloading):
constexpr int N = 42; // guaranteed to have no runtime memory
allocation;
// its value is folded into the executable
code.
of course, then you have a new keyword requirement for D, which
will likely go nowhere....
as for.. macro N = 42; ... well... yuk!
I presume enum N = 42; already guarantees the above anyway, so I
wouldn't be arguing for a change here. But if designing a
language from scratch, I would certainly not be considering
overloading enum for this purpose (nor would I be considering
using 'macro'!)
As it is, the syntax for expressing a manifest (enum) constant in
D already exists, and it won't likely change. The conflict is
semantic, not technical.
More information about the Digitalmars-d
mailing list