4 ms·
I once #defined strlen to return a short. This was in the days of the 16-bit to 32-bit transition on Windows, and I was running a project to eliminate spurious
by tjradcliffe 11y ago
I once #defined strlen to return a short. This was in the days of the 16-bit to 32-bit transition on Windows, and I was running a project to eliminate spurious warnings from our code. There were several hundred places where the return value of strlen was being assigned to a short, every one of which created a warning.
I was a senior developer but it was my first commerical job--I'd been in academia previously. I ran the change by the the most senior technical people in the company, all the way up to the guy who'd written the original application as employee #1. He OK'd it because, as he said, "strlen returns as short on the Mac anyway, and since our code runs on Mac as well as Windows it's a limitation we have to respect anyways."
A few years later the company stopped supporting the Mac.
A few years after that (and well after I'd left the company) one user site started getting crashes. I heard later that it took four senior devs a week to track down the cause, and much head-scratching because strlen was documented to return an int. They eventually found my #define, along with a comment that this eliminated so-many hundred warnings in the build, and that the change had been approved by the most senior people (I wasn't totally naive).
It turned out the problem at the specific site having the issue was users putting the entire contents of files into what amounted to tool-tips. It was totally unexpected user behaviour, but they'd found a place they could cache some useful data and we let them do it, so it should have worked.
Today I'd write a script that auto-edited all the cases where the problem occured, and regression test the hell out of it, but yeah: the '90's were a different time!
- unwind 11y agoI'd just like to point out that at least in the draft C89 standard (http://port70.net/~nsz/c/c89/c89-draft.html#4.11.6.3 http://port70.net/~nsz/c/c89/c89-draft.html#4.11.6.3), strlen() had the same prototype as it has today: in other words it returns size_t. Not int.