So, the other day I found again this old comic and it made me want to look for how many instances of swearing there are in my code. Much to my surprise, there's only one (and the game is nearly complete):
// Copy data from the old map to the new one
// <Sik> WTF I had to put the explicit cast to unsigned there because
// apparently substracting two uint16_t will result in a signed type...
// Gotta love type promotion rules
for (unsigned x = 0; x <= (unsigned)(src_x2 - src_x1); x++)
for (unsigned y = 0; y <= (unsigned)(src_y2 - src_y1); y++) { src_x1, src_y1, src_x2 and src_y2 are all of type uint16_t (also the former two are known to be smaller than the latter two). One would expect the result to stay unsigned, but integer promotion makes it signed int (because those types are smaller). Normally not an issue except because that makes it unpredictable with comparisons (since x and y are unsigned and I'd be comparing them against signed values were it not for the explicit cast).
Anyway, problem solved the obvious way with an explicit cast, and will probably leave it at that since it works just fine and is easy to read. Does anybody here know of a nicer looking solution though? Just curious, I don't really care.