www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - implicit or module-wide nogc

reply Gokhhy <gokhhy gmail.com> writes:
Is there a way to define an entire module as  nogc or otherwise 
make it so I don't have to qualify every single function as  nogc?
Jun 12 2018
next sibling parent reply Mike Franklin <slavo5150 yahoo.com> writes:
On Wednesday, 13 June 2018 at 06:45:27 UTC, Gokhhy wrote:
 Is there a way to define an entire module as  nogc or otherwise 
 make it so I don't have to qualify every single function as 
  nogc?
You can put attributes at the top of a module followed by a ":" to have them apply to everything below them. module mymodule; nogc: void nogcFunction1() { } void nogcFunction2() { } Mike
Jun 13 2018
parent reply Gokhhy <gokhhy gmail.com> writes:
On Wednesday, 13 June 2018 at 07:11:56 UTC, Mike Franklin wrote:
 On Wednesday, 13 June 2018 at 06:45:27 UTC, Gokhhy wrote:
 Is there a way to define an entire module as  nogc or 
 otherwise make it so I don't have to qualify every single 
 function as  nogc?
You can put attributes at the top of a module followed by a ":" to have them apply to everything below them. module mymodule; nogc: void nogcFunction1() { } void nogcFunction2() { } Mike
Thanks, just what I was looking for.
Jun 13 2018
parent reply Gokhhy <gokhhy gmail.com> writes:
On Wednesday, 13 June 2018 at 07:14:35 UTC, Gokhhy wrote:
 On Wednesday, 13 June 2018 at 07:11:56 UTC, Mike Franklin wrote:
 On Wednesday, 13 June 2018 at 06:45:27 UTC, Gokhhy wrote:
 Is there a way to define an entire module as  nogc or 
 otherwise make it so I don't have to qualify every single 
 function as  nogc?
You can put attributes at the top of a module followed by a ":" to have them apply to everything below them. module mymodule; nogc: void nogcFunction1() { } void nogcFunction2() { } Mike
Thanks, just what I was looking for.
Nevermind, it doesn't affect functions inside classes and structs. I would be interested in what influenced the design decision to make opting out of garbage collection so difficult.
Jun 13 2018
parent reply Mike Franklin <slavo5150 yahoo.com> writes:
On Wednesday, 13 June 2018 at 07:19:24 UTC, Gokhhy wrote:

 Nevermind, it doesn't affect functions inside classes and 
 structs.
Yeah, that's kindof unfortunate isn't it. Just do the same thing within the class/struct scope. class C { nogc: void nogcMethod1() {} void nogcMehtod2() {} }
 I would be interested in what influenced the design decision to 
 make opting out of garbage collection so difficult.
Because D is more evolution then intelligent design, unfortunately. Mike
Jun 13 2018
parent Steven Schveighoffer <schveiguy yahoo.com> writes:
On 6/13/18 3:24 AM, Mike Franklin wrote:
 Because D is more evolution then intelligent design, unfortunately.
I had to LOL on this, nice :) -Steve
Jun 13 2018
prev sibling parent Basile B. <b2.b2.b2.b2.b2.temp.temp.temp gmx.gmx.gmx.com.com> writes:
On Wednesday, 13 June 2018 at 06:45:27 UTC, Gokhhy wrote:
 Is there a way to define an entire module as  nogc or otherwise 
 make it so I don't have to qualify every single function as 
  nogc?
--- module module_wide-nogc; nogc: /* declarations or statements... */ --- But this is not considered as a good practice. 1. One can work on the module and miss the global nogc 2. unittest are affected (array literals for example must be declared static immutable) 3. it cannot be temporarily canceled. It depends on the context too. 200 slocs module or 5000 sloc module ? for a small one this could be ok.
Jun 13 2018