Errors, bugs, questions - page 1926

 
fxsaber:

if there will only be read-only operations in the future.

The compiler does not know (and should not know) what the future operations will be (otherwise the compile time would be hours instead of minutes)
 
A100:
The compiler does not know (and should not know) what the future operations will be (otherwise the compile time would be hours instead of minutes)
void OnStart()
{
  int a; // variable 'a' not used
}
 
fxsaber:

The compiler gets to line 1 - it gives a warning - because it does not analyse further operations, and the <a> variable can be initialised later. And if

 const int a;

it would give out an error because it cannot be initialized later (and the compiler does not analyze further operations and does not know, for example, that it will not be used further at all)

Everything is logical and does not depend on subjective preferences

 
A100:

The compiler gets to line 1 - it gives a warning - because it does not analyse further operations, and the <a> variable can be initialised later. And if

it would generate an error because it cannot be initialized later (and the compiler does not analyze further operations and does not know, for example, that it will not be used further at all)

Everything is logical and does not depend on subjective preferences

It is illogical why you cannot use a rubbish const-variable.

 
fxsaber:

It doesn't make sense why you can't use a rubbish const variable.

Provide an example of this use

         const int a;
can be written conventionally as
        int i;
        const int a = i;
        Print( a ) //случайное число... и что дальше?
 
A100:

Give an example of this use

Transfer to a function by reference and retrieve a value.
 
Комбинатор:
pass it to a function by reference and get the value.
What does it look like in the code?
 
A100:
What does it look like in the code?
void f(int& i)
{
   i = 5;
}

{
   int i;
   f(i);
}
 
Комбинатор:
where is the const ? (or didn't you read the last page?)
 

I'm actually against uninitialised variables of any kind and forbid them at compiler level, I just gave an example.

A100:
Where is const ? (or did you not read the last page?)
Yes, i did, but i must have been inattentive.
Reason: