Live data from Hacker News

4 billion if statements (2023)

andreasjhkarlsson.github.io

181–183 of 183 posts

Re: 4 billion if statements (2023)

#181

Earlier quoted context omitted.

It certainly would be normal to use else if (or switch) if you wanted to be picky but really such changes are inconsequential here. And I was trying to change just one line. Sadly I also had to quietly change stdlib.h to string.h as well.

If you wanted to avoid , you could use the poor man's strlen(), snprintf(0,0,"%s",argv[1]). For full input validation without adding any more statements, the best I can get (in ISO C) is uint8_t number = (argc Though with either function you may run into issues if the OS allows arguments longer than INT_MAX. To be defensive, you could use "%32767s" or "%*32767[0123456789]%n" instead, at the cost of failing inputs lon…

Marvellous, love it. Thank you.

Re: 4 billion if statements (2023)

#183
I really enjoy posts like this one because I always learn something. Sure the whole program can be written using bitwise comparison or modulus, but that's not the point. The thing I learned is how to map that into address space! That's a cool trick!
Post reply on HN