Path: news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: anton@mips.complang.tuwien.ac.at (Anton Ertl) Newsgroups: comp.lang.forth Subject: Re: THROW codes and ambiguous conditions Date: Sun, 01 Jun 2025 15:15:42 GMT Organization: Institut fuer Computersprachen, Technische Universitaet Wien Lines: 55 Message-ID: <2025Jun1.171542@mips.complang.tuwien.ac.at> References: <2025May31.080248@mips.complang.tuwien.ac.at> <2025May31.180736@mips.complang.tuwien.ac.at> Injection-Date: Sun, 01 Jun 2025 17:51:33 +0200 (CEST) Injection-Info: dont-email.me; posting-host="c0037f9683da863643a3d84328a19d41"; logging-data="2368054"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19bqpWID6gNLrXEA/DVRg4u" Cancel-Lock: sha1:FoDR52WfWS8d6mKxbuwehY613uo= X-newsreader: xrn 10.11 albert@spenarnc.xs4all.nl writes: >Actually, the error returns from system calls are negative >numbers. So I do approximately: > ( open file ) DUP 0 MIN THROW \ Now the result is a file channel id. >So I was puzzled at the term remapping. Indeed the man 3 errno >reveals that positive numbers are intended. It depends on the architecture how an error from a system call is indicated; on some architectures the result is only returned in one register, on some it's a register and a flag (IIRC the carry flag). In the latter case a set flag indicates that the register contains an error code, while a clear flag indicates that there was no error and the register contains the result. If there is only one register, you have to find out it the result is a success or an error. Many system calls are designed to produce a positive result (e.g., write() or read()), and using the negative number range for error results is the solution for that; that's why you are seeing the negated errno. It becomes tricky to do system calls like sbrk() and mmap() that return addresses, because in principle any bit pattern can be an address. But originally Unix and Linux reserved the high half of address space for the system, so these system calls, which return user-level addresses, could only return addresses where the MSB is clear. Towards the end of the 32-bit era, user space could reach up to 3GB, so just checking the sign was not enough, but there was still 1G of numbers that could be used as error returns. >This discussion proves that adhering to >the exact throw cause is of dubious value. There is apparently little usage of catching specific throw codes. E.g., I have never done that. However, throwing specific codes is a different issue. I have done so, and I have discussed with other people which existing throw codes are appropriate for which error. An example is shown in <2024Apr1.115659@mips.complang.tuwien.ac.at>: : gen-mask3 ( n -- x ) \ throw if =0 64 swap - dup 64 u< 0= -24 and throw -1 swap lshift ; Will 0 GEN-MASK3 give the error message "Too many open files" or "Invalid numeric argument" on ciforth? - anton -- M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html New standard: https://forth-standard.org/ EuroForth 2023 proceedings: http://www.euroforth.org/ef23/papers/ EuroForth 2024 proceedings: http://www.euroforth.org/ef24/papers/