What are the rules on declaring integers?

Good point! I've changed x to a byte. There should be a fairly good guarantee that will be an unsigned 8 bit integer when using any official Arduino core.