The index part is defined in latex.ltx, loaded by \makeindex, and can be overridden elsewhwere (e.g., in index.sty). The case is similar for make glossary.
<..control @..>
\def\#{\string\#}%
-_-_-
Within the source, we have a definition \chardef\#=‘\# which in immediate environment has the meaning of \# and in regular envirionment the meaning of \chat‘\#.
<..latex ltidxglo..>
\NewConfigure{wrindex}[1]{\concat:config\a:wrindex{#1}}
\let\a:wrindex\empty
\expandafter\ifx \csname @indexfile\endcsname\relax \else
\let\o:wrindex:=\@wrindex
\def\@wrindex{\a:wrindex \o:wrindex:}
\Configure{wrindex}
{<.control @.>\warn:idx{\jobname}%
\:wribefr\@indexfile}
\fi
\ifx \@glossaryfile\:UndDef \else
\let\:wrglossary=\@wrglossary
\def\@wrglossary{\:wribefr\@glossaryfile\:wrglossary}
\fi
\def\:wribefr#1{\title:chs{\html:addr
\hbox{\Link-{}{<.index haddr.>}\EndLink}}{}%
\edef\:temp{\write#1{\expandafter\string\a:idxmake{\RefFileNumber
\FileNumber}{\title:chs {<.index haddr.>}{\cur:th
\:currentlabel}}{\a:makeindex}}}\:temp}
\ifx \a:makeindex\:UnDef
\NewConfigure{makeindex}{1} \Configure{makeindex}{}
\fi
\ifx \beforeentry\:UnDef \def\beforeentry#1#2{} \fi
\NewConfigure{idxmake}{1}
\Configure{idxmake}{\beforeentry}
-_-_-
Without the \hbox we have sometimes a problem. Why?
The index command expandas to \begingroup \@sanitize \@wrindex and changes catcodes within \@sanitize. The \:wrindex needs to be careful with catcodes changes to avoid errors. For instance, a spacefactor in the following at oolatex
or braces in the following for htlatex.