4-character literal
Bill Baxter
dnewsgroup at billbaxter.com
Sat Jan 27 04:59:34 PST 2007
Rick Mann wrote:
> Joel C. Salomon Wrote:
>
>> Rick Mann wrote:
>>> Sadly, nothing's really as nice as just saying 'abcd'. What would it take to get multi-character literals added to the language?
>> In the process of learning to scan C (for a compiler theory class), I
>> first heard about those. Seems not-too-useful. If you want a number,
>> input the number; if you want a Unicode character, enter L'é‚£' (or
>> whatever the D equivalent is). Entering numbers in base 256 is asking
>> for trouble, especially with UTF-8 source.
>
> I gotta say, I think they're very useful. Multibyte-character issues aside, it can be a lot handier to see 'abcd' in a debugger than '61626364'. And handling multibyte characters isn't that big a deal...just include all the bytes. If the integer interpretation is 4 bytes, treat it as an uint. If it's more, treat it as a ulong, and issue appropriate warnings/errors when assigning. Pad the values out with zeros. I'm not sure I understand the resistance to the notion.
>
Probably it's just that most folks rarely ever have a need for such a
thing. And in the rare case that we do, the template solution doesn't
seem so bad.
Besides isn't the value of a multi-character literal going to be
dependent on the endianness of the machine you're running on?
So you're probably going to want to use it inside a
version(LittleEndian) {} else {} construct anyway. Might as well tuck
that away inside the MAKE_ID template.
--bb
More information about the Digitalmars-d
mailing list