Subject: Re: Numeric constants as strings

From: "Shawn O. Pearce" <[email-masked]>
Date: Mon, 19 Feb 2007 04:49:55 -0500

Junio C Hamano <[email-masked]> wrote:
> Andy Parkins <[email-masked]> writes:
> 
> > I'm working on bringing my hash width literals patch up to
> > date now that 1.5.0 has passed.  It's all been trivial apart
> > from one line:
> >
> > #define HASH_WIDTH_ASCII 40
> > -               printf("%-40s %s%s (%d subtrees)\n",
> > +               printf("%-" HASH_WIDTH_ASCII "s %s%s (%d subtrees)\n",
> >
> > This compiles, but I suspect that it's not going to do what I
> > want it to do.
> 
> Doesn't writing "foo" "bar" (two string literals next to each other)
> tell the compiler to concatenate them?

Yes, but here HASH_WIDTH_ASCII is a number...  wtf is the compiler
generating for the following?

  printf("%-" 40 "s %s%s (%d subtrees)\n",

I did not even realize that was legal C...  Now if the 40 was in
quotes (e.g. "40") then the concatenate rule would apply and we
would get a nice argument to printf.

-- 
Shawn.