To flesh out a little historical detail:
The primary defense of England from roughly 1700-1840s, was the Channel Fleet a powerful fleet kept permanently on station tacking upwind of the southern entrance to the "English" (and they wanted to keep it that way) channel. Unlike other fleets or individual ships, the Channel fleet never went anywhere it just tacked back and forth in a small area just to have the wind gauge so they could intercept any one trying to reach England or block the channel.
With the shore and home "just right over there" the Channel fleet developed several practices not found in the rest of the British Navy. One of them was allowing wives aboard ship. Although, contrary to common sources, it appears this allowance was restricted to officers, both commissioned and warranted, unless the ship was actually in port. Because the ships spent weeks or months on station and women of reproductive age at that time spent 2/3rds of their life pregnant or nursing, births at sea were inevitable.
On ship, sailors on warships lived and ate on the gun deck literally squeezed around the guns so in the popular imagination, any birth at sea to a wife of the crew would have to happened on the gun deck between the guns, hence "son of a gun."
In reality, they would give birth in a either the officers cabin, the surgeons cockpit in the bow or weather permitting, on the deck.
Pretty sure one of Nelson's officers famously recorded the birth of "a son of the gun" to his Master Mate's wife.