float.sizeof should be 4
Salih Dincer
salihdb at hotmail.com
Tue Sep 24 14:06:50 UTC 2024
On Tuesday, 24 September 2024 at 13:36:06 UTC, deadalnix wrote:
>
> sizeof is a property here, not a value, and that property has
> for value 4, and type size_t.
When we want to look at the size of an enum, why is it 128 bytes
if its original type is string? It's off topic but I want to give
an example:
```d
enum iColor : short { R, G, B } //*
enum sColor : string
{
R = "red", G = "green", B = "blue"
}//*/
template ByteSize(E) if (is(E == enum))
{
alias T = imported!"std.traits".OriginalType!E;
enum ByteSize = T.sizeof * 8;
}
import std.stdio;
void main()
{
ByteSize!iColor.writeln(" == ",
iColor.sizeof * 8);
ByteSize!sColor.writeln(" == ",
sColor.sizeof * 8);
String.sizeof.writeln; // 48
}
struct String
{
immutable(char)[] str;
size_t a, b, c, length;
}
```
SDB at 79
More information about the Digitalmars-d
mailing list