5 ms·
const MAX: u32 = 100; // Compile-time constant let x: u32 = 10; // Cannot be changed If x cannot be changed, how does it differ (meaningfully) from
by steeleduncan 1mo ago
const MAX: u32 = 100; // Compile-time constant
let x: u32 = 10; // Cannot be changed
If x cannot be changed, how does it differ (meaningfully) from a compile time constant in a safe language, ie in a case of no raw pointers
- v0id_isgood 1mo agoconst can be used in places that need a compile-time-known value (like a fixed array size). let can't, even if it obviously holds a fixed number.
- bramadityaw 1mo agoisn't there a way to infer that from context? like if the variable is declared with the Comptime role. Some guy said that the const keyword was a mistake C made that is then blindly followed by its successors.
- deleted 1mo ago[deleted]