When touring Europe from the hatch of my M113, or from my Austin Healy 3000 a lifetime ago, I noticed a line of pigeon holes about two meters apart and about two meters down from the top of the walls. It turned out that those holes were where the defender anchored his wooden structures called “hoarding” having nothing to do with storing. Hoardings were used to extend the defensive structure so that objects could be dropped directly through the floor onto people operating against the base of the walls. In addition, the hoardings had protected firing positions firing bolts or arrows through what were called “loops”. There were archer’s loops, and crossbowman’s loops; archer loops were vertical, crossbowmen loops were horizontal.
Normally any loop cut into wood or stone had a narrow opening on the outside to reduce the odds of an arrow or bolt hitting the archer/crossbowman. The inside was wider to allow the archer to move left and right for a better shot. Guns made too much noise and smoke so any gun ports have the wide side outside, narrow inside. The Fort San Juan de Ulloa at Vera Cruz Mexico shows both.
The narrowness of the loops of ancient/medieval defenses suggests that sniper fire was alive and shooting during sieges. Moving about a fortification or the besiegers positions in range of a bow was a hazardous proposition. Richard the Lion Heart was a sniper’s victim. In the Japanese film ”Kagemusha” about how Takeda Shingen, Lord of Kai, was shot by a sniper in 1573, lured by his love of music to his favorite spot.
The defenses are arrayed in depth with outer works to defend the gates, fortified gates, inner courts and the castle "keep", donjon, or citadel which is the last line of defense.
There are a few objects de guerre on the walls not used for firepower, but for waste disposal both garbage and the other stuff. The latter were called “garderobes” of the pre-flush days depending on gravity without updraft. These look just like machicolations or hoarding except the firing port is a bit larger.