size_t.sizeof == 2 && __LINE__.sizeof == 4

Walter Bright via Digitalmars-d digitalmars-d at puremagic.com
Mon Jul 10 12:41:48 PDT 2017


On 7/10/2017 5:41 AM, Luís Marques wrote:
> for 16 bit targets

Having developed C/C++ on 16 bit targets for a couple decades, I have some 
curmudgeonly perspective.

1. having __LINE__ as size_t is madness. If I was responsible for that, shame on me.

2. a 16 bit type for 16 bit targets is plenty good enough. Consider that 32 bits 
on 16 bit targets is code bloat EXPENSIVE, and code bloat is a huge problem on 
16 bit targets. You're just not going to have 64000 line files, because the 
generated code won't fit in 16 bits. Even if you constructed a case, having the 
counter wrap around is little more than a very minor aggravation.

3. C++ worked on 16 bit code before exceptions and RTTI. Exceptions and RTTI are 
completely unworkable on 64K machines, and even on 640K machines. The STL is 
completely unworkable on 640K machines, because it is just too big.

4. 640K programming in C++ is not practical without near/far support. D has no 
such support, and neither does Standard C++.

5. C++ on a 64K machine is like using a tank to get to the grocery store.

6. __LINE__ is typed `unsigned` everywhere I've seen, including with 16 bit 
compilers.

== Some Conclusions ==

1. __LINE__ should be `uint`. Negative lines make no sense.

2. Exceptions are useless on 16 bits, so class Exception has no purpose.

3. D doesn't have near/far and won't be suitable for 640K programming.

4. D for 64K programming is possible in 'betterC' mode.

5. D's 32 bit int sizes are not very workable for 16 bit code. shorts will be 
promoted to 32 bits. Trying to change this in the compiler logic for 16 bit 
targets is an unknown amount of work.

6. D for 16 bits wouldn't really be D, it would be a D variant with different 
semantics and capabilities. (Like C++ for 16 bits.)

== Bottom Line ==

Trying to make D into a useful compiler for 16 bit programming is a bit of a 
quixotic quest. But it probably could be bludgeoned into doing something 
credible with it if needed to satisfy a bullet point requirement. __LINE__'s 
type is hardly the only problem.

What is the goal/reason/rationale for making a 16 bit D target?


More information about the Digitalmars-d mailing list