Compile time int to string conversion in BetterC
Paul Backus
snarwin at gmail.com
Fri Aug 19 13:47:41 UTC 2022
On Friday, 19 August 2022 at 10:22:25 UTC, bauss wrote:
> Is there a reason why .stringof is implementation defined and
> not clearly defined in the spec how types and declarations
> should be treated when being "converted to a string"?
>
> I find it really odd that it's implementation defined and you
> essentially can't rely on it anywhere.
>
> It's something that has baffled me a lot.
>
> Like are there something I'm missing that means it cannot be
> specified?
Basically, `.stringof` is what the compiler uses when it needs to
display something in an error message. If it were locked down in
the spec, then making improvements to error messages would in
some cases require a deprecation cycle.
That said, it might still be worth specifying the behavior in a
few specific cases—e.g., guaranteeing that `.stringof` on an
integer value will always produce a valid integer literal.
More information about the Digitalmars-d-learn
mailing list