Isn't that undefined behavior according to the standard? I am no expert but
ledMode = (ledMode+1) % 8;
will always work