Transferring 32 bits

Salih Dincer salihdb at hotmail.com
Thu Aug 25 12:18:19 UTC 2022


Hi All,

Transferring 32 bits (4 characters) of data from a data source, 
for example to the S structure takes place...

Everything is fine with the constructor but I can't keep the 
object alive with the foo() convenience function! My sample code 
is like this:

```d
import std.stdio;

struct S
{
   char[size] bytes;

   alias toString this;
   string toString() const
   {
     scope res = [ cast(string) bytes ];
     return res[0];
   }
}

string foo(char[size] bytes)
{
   scope res = S(bytes);
   return res.toString(); // problem here
}

enum size = 4;
void main()
{
   char[size] text = "abcd".dup;

   auto m = S(text);  // test ok
   assert(m == text);

   foo(text).writefln!"(%s)"; // (¿)
}
```

SDB at 79



More information about the Digitalmars-d mailing list