braceless with statements
kdevel
kdevel at vogtner.de
Sun Nov 14 16:51:01 UTC 2021
On Sunday, 14 November 2021 at 15:45:13 UTC, Ogi wrote:
[...]
> Braces and indentations keep things sane:
>
> ```D
> struct S { int x; }
> S s;
> with (s) {
> /*
> lots of code here
> */
> x = 42; //is this s.x? The answer is always yes.
> }
> ```
Wrong: replace /* lots of code here */ with int x:
```D
$ cat xxx.d
struct S { int x; }
void main ()
{
S s;
with (s) {
int x;
x = 42; //is this s.x? The answer is always yes.
}
import std.stdio;
writeln (s);
}
$ dmd xxx
$ ./xxx
S(0)
```
More information about the Digitalmars-d
mailing list