Is there any real reason to use "const"?

rempas rempas at tutanota.com
Mon Jan 24 16:41:00 UTC 2022


On Monday, 24 January 2022 at 15:40:56 UTC, Walter Bright wrote:
> Not sure what you mean. This compiles:
>
>   int foo(const int);
>
>   int bar(int i)
>   {
>     return foo(i);
>   }

Actually this compiles but what I thought that didn't was 
something like this:

```
void mul_num(int num) {
   num *= 2;
}

void main() {
   const int number = 10;
   mul_num(number);
}

```

But it turns out that it compiles but I would swear that I tried 
something similar to this and it wouldn't compile on both D and C.


More information about the Digitalmars-d mailing list