Local variable disappears.

SarK0Y sark0y at protonmail.com
Mon Dec 22 21:49:10 UTC 2025


On Monday, 22 December 2025 at 17:05:16 UTC, bauss wrote:
> On Monday, 22 December 2025 at 17:03:48 UTC, SarK0Y wrote:
>> On Monday, 22 December 2025 at 16:54:56 UTC, bauss wrote:
>>> On Monday, 22 December 2025 at 13:53:54 UTC, SarK0Y wrote:
>>>
>>> You have this wonderful line nuking your memory:
>>>
>>> ```
>>> *map = 0;
>>> ```
>> Thanks for Your reply, but i disagree..
>>
>> ```D
>>   map.name = "name1";
>>   *map = 0; // if it torpedoes memory
>>     map.prnt; // then sigsegv must be here
>>     simply_print_time ("start tst for __emp");
>>     map.prnt; // but it's here
>> ```
>
> It is undefined behavior, so it can happen at anytime, anywhere.

unfortunately, situation been not that simple == seems there is 
problem to initialize class GmpInt properly: i made two funcs to 
create class..
[zz.mk](https://github.com/SarK0Y/DLang/blob/556fefa36e51b46a80de3717d8c495842c36224f/source/class_gmp_z.d#L141)

```D
  static zz* mk () {
         auto __zz = new zz(0);
         auto size_zz = __traits (classInstanceSize, GmpInt);
         auto alloc_zz = cast (zz) malloc (size_zz);
         alloc_zz = __zz.dup;
         alloc_zz.name = "alloc_zz";
         alloc_zz.prnt;
         zz* ret = &alloc_zz;
         ret.prnt;
         return ret;
     }
```
[zz._mk](https://github.com/SarK0Y/DLang/blob/556fefa36e51b46a80de3717d8c495842c36224f/source/class_gmp_z.d#L152)

```D
     static zz* _mk()
     {
         auto __zz = new zz(0);
         zz* ret = &__zz;
         return ret;
     }
```
in short, not sufficient allocation is very culprit here..

PS. variant w/ malloc runs more stable :)


More information about the Digitalmars-d-learn mailing list