Comment

Comment by sltkr

This fails on overflow: if N == INT_MAX then your loop doesn't terminate and actually invokes undefined behavior in C.

The safe way to write it is:

    for (int i = 0; i < N; ++i) {
        something(array[N - 1 - i]);
    }
(or with size_t instead of int depending on the type of N)
parent sltkr 1 day ago

No comments yet

Be the first to share your thoughts.

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton