A cheap way to add a default unit of measure to an argument is to say
cm one can use any legal unit of measure). If
#1 is a number without a unit attached, the assignment will leave nothing to typeset in the box, which will have zero width. Otherwise
cm will be typeset.
So here's a way:
This is a box of #1 by #2 (default unit centimeters):\hfill
\testforunit we perform the test on
cm if necessary and store the requested length in
\dimen#1. The construction of the box is done with those two length but in a group where
\fboxsep is set to
\fboxrule, so that the frame will have the exact requested dimensions. In the example the first and second boxes are identical.
As suggested by Joseph, here is the "official" LaTeX kernel way of defining