'Son of a Gun'
Three centuries ago the expression described the son of a Gunner in a rather uncharitable way.
In olden times, the 'train of artillery' always included camp followers, among them 'ladies of easy virtue' with whom Gunners, being human, were apt to form unblessed liaisons. There being neither pill nor condom in those days bad luck or carelessness inevitably 'brought forth illegitimate issue', as the more polite historians say.
Now jealous members of the Infantry and Cavalry who did not enjoy the same 'home comforts', and as we know had a poor opinion of our ancient brethren in any case, would call the misbegotten infant a 'son of a gun', implying that not only was it a bastard of low estate but that its father was one also.
Although the original significance of the expression has long since faded we still use it; as a soldier in Kiwi fashion may address his friend as 'You old bastard', so may he substitute 'You old son of a gun' provided he says it with a smile!