It is well established in Star Trek: The Next Generation that female superior officers are normally referred to as sir. This is applied to Dr. Crusher, Counselor Troi, Cmdr. Shelby, Maj. Kira, Lt. Dax, and numerous admirals. This obviously fits in well with the egalitarian ideals of Star Trek.
This convention is made explicit in "Thine Own Self":
DATA: Counsellor, have you been promoted in my absence?
TROI: That's right. Which means from now on you can call me sir.
DATA: Yes, sir.
In Addition, the first episode of Star Trek: Voyager, "Caretaker" contains this dialog:
KIM: Thank you, sir.
JANEWAY: Mister Kim, at ease before you sprain something. Ensign, despite Starfleet protocol, I don't like being addressed as sir.
KIM: I'm sorry, ma'am.
JANEWAY: Ma'am is acceptable in a crunch, but I prefer Captain. We're getting ready to leave. Let me show you to the bridge.
which again establishes that sir is the norm, although Capt. Janeway doesn't prefer it.
Did this usage of the honorific sir start with ST: TNG or does it predate TNG in either sci-fi or the real world?