News for hackers. Stuff that matters.

sincerel

Re:Why numbering should start at zero (1982) on Thursday December 15, 2016 @02:23PM (#13187370)
It lets you translate freshman level math problems with the same indices. As soon as you deal with Fourier transforms, Vandermonde matrices, polynomials, or pretty much anything where the array index is related to the value in the array, zeros make more sense. People like 1-based because they're familiar with it, and that's fine, but pretending that it makes more sense because their familiar with some math that uses 1-based is silly.
Re:Writing C software without the standard library on Tuesday November 29, 2016 @12:51PM (#13064675)
I use stdint.h too, but I'm honestly curious if there is any common platform around today where one of the following asserts fails:

    int main() {

        assert(sizeof(signed char) == 1);
        assert(sizeof(short)       == 2);
        assert(sizeof(int)         == 4);
        assert(sizeof(long long)   == 8);

        return 0;
    }
I'm not interested in the language lawyering, because yes I know the standard provides more freedom to compilers. I just think those definitions are very universal for any real computer that would otherwise run my software. Please don't bring up Windows 3.1, that's about as relevant to most of us a PDP-11.

And for what it's worth, using typedefs based on the above provides more readable printf strings. This is hideous:

    int main() {

        int64_t portable = 123;
        printf("Ugly: %" PRId64 "\n", portable);
        
        return 0;
    }
Where this is acceptable:

    int main() {

        long long palatable = 123;
        printf("Better: %lld\n", palatable);
        
        return 0;
    }