Kissing the gunner's daughter
While men were usually flogged on their backs while standing upright, tied to the mast or a grating, boys were traditionally punished on their bare buttocks in bent-over-object positions. One of these positions was called "kissing the gunner's daughter" because of the way a cannon was used.
The delinquent boy (or man) was laid lengthways over the barrel of a field gun (cannon) on the main deck. His hips rested on a folded hammock or mattress and his wrists were tied together underneath so that he was embracing the barrel. Thus positioned and restrained, he was flogged across the naked buttocks with a cat o' nine tails made of whipcord. The lashes were given with pauses of 10 or 15 seconds in between to ensure that the delinquent fully experienced the pain, and also because the tails could become entwined and required separating. A flogging of 48 lashes, which was the maximum, could thus take 8 to 12 minutes. The whipping was also sometimes given with a cane or birch instead of a cat.
The administration of corporal punishment over a gun was so popular that aboard ships where no operational artillery mouth was present, a practice gun was used. However for less formal chastisement, the miscreant's stern was similarly exposed by bending or being tied over a capstan or bitt(s) — both also publicly on deck — or inside, e.g. 'brought to the chest', or even ordered to grab his ankles on the spot.
Straddling or sideways
In a variant that is shown in the first image and described in some spanking stories, the boy or man is straddling the cannon so his legs are spread to either side. This variant may have been used at least on some of the ships, as the rounded shape of a cannon's barrel would have lent itself for it. However in order to straddle, the delinquent would either have to keep his trousers up or take them off altogether, not just lower them.
There is also a sideways variant, as exemplified in the other image to the right.
The 1984 film The Bounty (a remake of Mutiny on the Bounty) starring Mel Gibson and Anthony Hopkins, shows this type of punishment being administered to a young sailor for neglecting his duties.