What do the words "in" and "out" in D mean?

What does it mean and do keywords inand outin D? From a look at the functions that use them for their parameters, I understand that the keyword is inused to enter the function, and the keyword is outused for parameters that are mainly passed by reference.

Is this understanding correct, and what do they actually allow or forbid the programmer to do?

+4
source share
1 answer

Yes, you basically understand that. inexpands to const scope, which means that you cannot change the variable (or whatever it indicates), and also should not contain a link to it anywhere ( scopeactually not implemented in most cases). Basically, init looks do not touch.

outmeans that this variable takes a value. It is very similar to ref- the changes inside the function are also visible from the outside - with the slight difference that the out variables are initialized to their normal init value, clearing the value that they had before the function was called.

Basically, void foo(out int a) {}==void foo(ref int a) { a = 0; /* inserted automatically */ }

+8
source

Source: https://habr.com/ru/post/1528171/


All Articles