If you try
\documentclass{article}
\begin{document}
\newlength{\ccc}{10pt}
\the\ccc
\end{document}
you get

Can you see why? Because \newlength
takes one argument, not two, so {10pt}
is typeset. Next, the value of \ccc
is shown, which is still 0pt
.
If you do
\newlength{\ccc}{\dimexpr\textwidht-100pt}
then TeX tries to typeset {\dimexpr\textwidth-100pt}
which raises an error about \dimexpr
, which is not legal in that context.
There is a rationale. As a general rule, registers should be allocated in the preamble and their value can be set anywhere needed.
You first allocate the register, then set it. Allocation for a new length register is done with \newlength
; setting a length register is done with \setlength
.
\documentclass{article}
\newlength{\ccc}
\begin{document}
\setlength{\ccc}{\dimexpr\textwidth-100pt}
\rule{\ccc}{10pt}
\end{document}
By the way, if you want to fill the rest of the line with a 4pt thick rule, there is a different method that doesn't require measuring.
\documentclass{article}
\newcommand{\filltoend}{%
\unskip\nobreak\leaders\hrule height4pt\hfill\mbox{}\par
}
\begin{document}
Some words\filltoend
Some words and some other words
Some words and some other words
Some words and some other words
Some words and some other words
Some words and some other words\filltoend
Some words and some other words
Some words and some other words
Some words and some other words
Some words and some other words
Some words\filltoend
\end{document}

\usepackage{calc}\newlength{\ccc}\setlength{\ccc}{\textwidth-100pt}
\dimexpr
rather than calc, but either work.