You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
6:
7: some_primes[0] = 2;
8:
9: const char FIRST = some_primes[0];
^^^^^^^^^^^^^^
(003_arrays.c3:9:24) Error: The expression must be a constant value.
8:
9: const char FIRST = some_primes[0];
10:
11: const char FOURTH = some_primes[3];
^^^^^^^^^^^^^^
(003_arrays.c3:11:25) Error: The expression must be a constant value.
"const" indicate that the variable can't be re-assigned and it's the case with my example code. Also I found Constant expressions and I doesn't understand why it can't work because FIRST and FOURTH take integer value. I'd agree if these variables were pointers or references, but it's not the case.
Like some others languages (Nim, Rust ...) I propose "let" statement to declare symbols are single assignment variables: After the initialization their value cannot change.
import std::io;
fn int main()
{
char[8] some_primes = {1, 3, 5, 7, 11, 13, 17, 19};
some_primes[0] = 2;
let char first = some_primes[0]; // OK
let char fourth = some_primes[3];
first = 8; // Error, let variable can't be re-assigned
const usz LENGHT = some_primes.len;
io::printfn("First: %d, Fourth: %d, Length: %d", first, fourth, LENGHT);
return 0;
}
Thanks.
The text was updated successfully, but these errors were encountered:
EchoPouet
changed the title
Variable const error, explain me why
Variable const error and immutable proposition.
Jan 20, 2025
EchoPouet
changed the title
Variable const error and immutable proposition.
Variable const error and immutable proposal.
Jan 20, 2025
Hello,
I would like convert a simple Zig code to test C3 features, the code:
And I have this error mesage:
"const" indicate that the variable can't be re-assigned and it's the case with my example code. Also I found Constant expressions and I doesn't understand why it can't work because FIRST and FOURTH take integer value. I'd agree if these variables were pointers or references, but it's not the case.
After explanation in Discord I made a proposal.
Like some others languages (Nim, Rust ...) I propose "let" statement to declare symbols are single assignment variables: After the initialization their value cannot change.
Thanks.
The text was updated successfully, but these errors were encountered: