News for hackers. Stuff that matters.
Re:SQLite Release 3.37.0 by derefr on Saturday November 27, 2021 @11:34PM (#29366183)
Presumably the point of the strict typing forbidding aliases here, is to force the developer to realize/acknowledge that SQLite does not in fact have separate internal native types with these names.

It's like the modern C convention of avoiding "int" in favor of u8/u16/u32/u64. Rather than pretending "int" is a separate thing, you have to explicitly choose and acknowledge the concrete primitive type you're really getting, and explicitly opt into the semantics that use of that concrete primitive type implies.

Re:SQLite Release 3.37.0 by nayuki on Sunday November 28, 2021 @12:00AM (#29366298)
Not a great analogy because the semantics of the classic C types still leak through. For example, ((uint16_t)0xFFFF) * ((uint16_t)0xFFFF) would cause undefined behavior if int is 32 bits wide, due to implicit arithmetic promotions.

Also, many APIs of the C standard library are defined to take or give char/int/etc., and it takes effort to translate between those types and u8/u32/etc. in a safe way that works on all platforms.

Re:SQLite Release 3.37.0 by derefr on Sunday November 28, 2021 @01:29AM (#29366678)
That's not because "int is 32 bits wide", though; that's because you're on a machine whose native register size is more than 16 bits, and so your processor's MUL instruction likely expects to always write the product to a 32/64-bit destination register, even if the source registers are both 16-bit.

IMHO C is far too lax with things like this; an ideal systems language would force you to annotate maths operations with the "working precision" for each operation, making explicit any promotion done to the inputs before the math happens. And then, if your "working precision" exceeded the destination variable's size, you'd also be forced to do an explicit demoting cast, just as if you were assigning from a declared larger-sized variable.

Yes, it'd be mostly irrelevant for everyday int math stuff; but it'd make things so much clearer as soon as you started working with floats (where you'd have to explicitly opt into Intel's 80-bit extended "working precision.")

Re:SQLite Release 3.37.0 by the_duke on Sunday November 28, 2021 @03:10AM (#29367113)
Rust requires explicit conversions for numeric types for exactly the reasons you mention.
Re:SQLite Release 3.37.0 by derefr on Sunday November 28, 2021 @12:39PM (#29370935)
Most systems languages (that aren't C) force you to be explicit about demoting casts between formal variables; that's the easy part. But no language I know of (not even Rust) gets rid of implicit promotion during math operations, in favor of 1. forcing you to specify the size of the destination register you want the instruction to use (i.e. the working precision), and then 2. requiring an explicit demoting cast if the destination formal variable is smaller than the working precision you specified.

I mean, C's inline assembler, and LLVM IR, both require this; but they also require you to specify which work register you're talking about, rather than just the size, which breaks the conceit of a "portable systems language."

Re:SQLite Release 3.37.0 by ComputerGuru on Sunday November 28, 2021 @11:11AM (#29369995)
Yup. Most newcomers to SQLite are bitten hard by the fake datetime support.