On the old sailing ships virtually every inch on space was a work space. When in port, wives and girlfriends were allowed on board but had to remain out of the way of ongoing work. On occasion a woman would go into labor and with the lack of any infirmary, the safest place to deliver was in the space between two cannon. Any baby born there was henceforth referred to as a "son of a gun".
In a Coast Guard Auxiliary boating course I took they spent an entire evening on phrases that have evolved from old nautical sayings. It was very interesting.