# How does \pgfkeysvalueof work?

With this minimal example

\documentclass{report}
\usepackage{tikz}

\begin{document}
\tikzset{
line width  = 5cm,
CC/.initial = 7cm
}
It doesn't works :\pgfkeysvalueof{/tikz/line width}

It works : \pgfkeysvalueof{/tikz/CC}
\end{document}


I can't get the value of line width, on the contrary of CC. Why? Is it because CC is stored like plain text and line width is not? How can I achieve my goal?

-

The shown difference has nothing to do with how \pgfkeysvalueof works. This macro simply expands to the given key, i.e. it is defined as \csname pgfk@#1\endcsname, so you get \pgfk@/tikz/CC and \pgfk@/tikz/line width (using \csname you can have spaces and other non-letters in the macro name).
The difference is in the way these keys were defined. The /tikz/line width got defined as .code={\tikz@semiaddlinewidth {#1}}. This defines a macro called \pgfk@/tikz/line width/.@cmd which holds that code and stores the values somewhere else. If you use the key PGF/TikZ (i.e., pgfkeys) checks if a .@cmd is defined and executes that code.
Now, /tikz/CC is defined using .initial which stores the 7cm value directly in in the key, i.e., in the macro \pgfk@/tikz/CC. You then can get the value again using \pgfkeysvalueof{/tikz/CC} which expands to this macro.
So, you can't just use \pgfkeysvalueof on arbitrary keys you didn't define yourself and hope they work. The internal implementation can be more complicated than a simple assignment. In the case of the line width I can help you. The final line width is stored in \pgflinewidth which is a dimension register, i.e., you can use it using a factor like 0.5\pgflinewidth.