[dmd-beta] dmd 2.064 beta take 2

Leandro Lucarella luca at llucax.com.ar
Thu May 16 00:51:14 PDT 2013


Rory McGuire, el 16 de May a las 08:48 me escribiste:
>   struct S
>   {
>       immutable int c = 123; // I agree with Walter, what if this is far
> away from the constructor
>       this(int i) { c = i; }
>   }
> 
>   struct S
>   {
>       immutable int c = 123; // This should be static, compiler issues error
>       // No constructor
>   }

There are cases where you might want this. Suppose you're implementing
a network protocol and you have a header to indicate what kind of packet
you have. Example:

struct P1 {
        immutable int type = 1;
        int param1;
}

struct P2 {
        immutable int type = 2;
        long param1;
}

The type field *needs* to be part of the struct layout so is sent
through the wire, but it won't change for a particular struct, ever.
Remember that memory layout matters in a struct.

I know there are ways around this, I'm just saying there are even use
cases for that case too.


-- 
Leandro Lucarella (AKA luca)                     http://llucax.com.ar/
----------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145  104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------
Yo soy Peperino, mártir latino, venid al asado pero traed el vino.
	-- Peperino Pómoro


More information about the dmd-beta mailing list