It is the year 2020: why should I use / learn D?
Walter Bright
newshound2 at digitalmars.com
Wed Nov 14 23:07:00 UTC 2018
On 11/14/2018 9:22 AM, kinke wrote:
> * Sane basic types. No need to include a header for the definition of `size_t`,
> no distinct basic types overlap (C++ long, wchar_t etc.; not 4 distinct types
> for a byte - C++ `char`, `signed char`, `unsigned char`, and planned `utf8_t`].
It's amazing how much time goes into dealing with C++'s fluid notions of the
sizes of those types. "unsigned long" is just awful, varying from memory model
to memory model, from platform to platform, especially when C++ uses it for name
mangling.
I've wasted endless hours with this, and I know what I'm doing with it. I see
others doing it, too. Look at all the countless C++ .h files which start with
something like:
#include <stdint.h>
/* ELF file format */
typedef uint16_t Elf32_Half;
typedef uint32_t Elf32_Word;
typedef int32_t Elf32_Sword;
typedef uint32_t Elf32_Addr;
typedef uint32_t Elf32_Off;
typedef uint32_t elf_u8_f32;
or those windows.h "WORD" declarations. Or in phobos\etc\c\zlib\zconf.h:
typedef unsigned char Byte; /* 8 bits */
typedef unsigned int uInt; /* 16 bits or more */
typedef unsigned long uLong; /* 32 bits or more */
Every C++ project reinvents this.
Just not having to deal with "is `char` signed or unsigned? will that affect my
existing code? does my code still work if `int` is 64 bits?" is a big win.
More information about the Digitalmars-d
mailing list