3 ms·
> an integer where the type system would ensure that it is always between 1 and 12 How does Pascal handle overflow/underflow? E.g. Month 10 + Month 11 = Month
by munchler 2y ago
> an integer where the type system would ensure that it is always between 1 and 12
How does Pascal handle overflow/underflow? E.g. Month 10 + Month 11 = Month 21?
- eddsolves 2y agoI assume modulo?
- loeg 2y agoUh, seemingly, yeah. 10+11 = 21. No bounds checking on addition or assignment. https://onlinegdb.com/3KhhaReLV https://onlinegdb.com/3KhhaReLV
- int_19h 2y agoThat is just this one particular implementation of Pascal (unsure which one). The language spec does say that it is an error to assign a value out of range, but as far as what this actually means, it only says that "a complying processor is required to provide documentation concerning its treatment of errors".
- dannymi 2y ago$ cat a.pp {$R+} var a: 1..12; b: 1..12; c: 1..12; begin a := 10; b := 11; c := a + b; Writeln(c) end. $ fpc a.pp Free Pascal Compiler version 3.2.2 [2021/05/19] for x86_64 Copyright (c) 1993-2021 by Florian Klaempfl and others Target OS: Linux for x86-64 Compiling a.pp Linking a 12 lines compiled, 0.1 sec $ ./a Runtime error 201 at $00000000004010D8 $00000000004010D8 $0000000000422EEC