For example, I once got in to an argument about how to handle code like this:
#include <stdint.h>
uint32_t rotate(uint32_t i, int bits) {
return (i>>bits) | (i<<(32-bits));
}
Whether this should return i if we rotate by 0 bits (like it does in GCC) was a discussion I had with the clang developers, and, lo and behold, we get this:If the value of the right [shift] operand is negative or is greater than or equal to the width of the promoted left operand, the behavior is undefined.
As an aside, this works:
#include <stdint.h>
uint32_t rotate(uint32_t i, uint32_t bits) {
return (i>>(bits%32)) | (i<<(-bits%32));
}
Because, as per the C99 standard:If the quotient a/b is representable, the expression (a/b)*b + a%b shall equal a
And:
a result that cannot be represented by the resulting unsigned integer type is reduced modulo the number that is one greater than the largest value that can be represented by the resulting type
Likewise, POSIX also means that every system call my open source code does, with the exception of chroot() and setgroups(), is defined in POSIX [1].
The entire environment to make my open source software only depends on POSIX utilities to build, and, indeed, it can build in both a Busybox based and a GNU based environment. For example, none of the filenames in my project have a `-` (dash) in them because, until POSIX 2024, one could not have a `-` or `/` in a filename used by Make, and yes my code builds with a strictly POSIX Make.
I no longer use Python for any of my open source because Python doesn’t have a stable standard to develop against; namely the Debian team got on my case I was using a Python2 script in 2020 when Python2 was made unsupported and I’m not going to play catch up should Python3 (or Perl) ever encounter the same fate Python2 has.
Instead, I write my scripts in Lua 5.1 these days. While Lua 5.1 isn’t a formal standard, the original implementation of Lua 5.1 (or a later version of Lua) has been implemented many times in many languages. There are two independent C implementations of Lua 5.1 in C, and there are also implementations in Go, C#, Javascript, Rust, and so on.
[1] /dev/urandom is also not defined in POSIX, but this is a runtime, not compile time issue, and writing a separate utility to put random bits in a normal file called /dev/urandom is one way to solve the issue.