I wrote an AR archive (.a files) parser in D
IchorDev
zxinsworld at gmail.com
Tue Aug 6 14:55:50 UTC 2024
On Sunday, 4 August 2024 at 20:14:50 UTC, Renato wrote:
> Just announcing here in case someone may be interested in that
> (the code is very easy to read) and wants to give some feedback
> on my usage of D
First of all, you should really be using `const` instead of `in`.
Second, do not cast from `const(ubyte[])` to `string`. This is a
violation of D’s type system. `string` is an alias of
`immutable(char)[]`. You’re casting to `immutable`—never cast to
`immutable`! Immutable data must never change during the lifetime
of a program, but `const` data may be changed from elsewhere
(e.g. another thread), so this cast violates all the assumptions
we make for immutable data! Instead, you should cast to
`const(char[])` in those places.
You also cast to immutable
[here](https://github.com/renatoathaydes/dar/blob/364494cfa18c884621c9ea92a800e281e9e4daac/source/dar.d#L122).
Since both mutable and immutable data implicitly cast to `const`,
if you want to take both as parameters, then always make your
parameters `const`.
More information about the Digitalmars-d
mailing list