Re: Numeric constants as strings

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Andy Parkins <andyparkins@xxxxxxxxx> wrote:

> 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",

The standard two-step goes

#define STRINGIFY(foo) STRINGIFY_REALLY(foo)
#define STRINGIFY_REALLY(foo) #foo

The purpose of STRINGIFY_REALLY is to macro-expand the argument foo.  If
you just invoked STRINGIFY_REALLY

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

you'd get

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

which is not what you wanted.  However,

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

will do the right thing.

-- [mdw]
-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]