DIP62: Volatile type qualifier for unoptimizable variables in embedded programming

Artur Skawina via Digitalmars-d digitalmars-d at puremagic.com
Tue Jul 15 12:18:50 PDT 2014


On 07/15/14 20:20, Johannes Pfau via Digitalmars-d wrote:
> (For example, in gcc even a force inline attribute does not inline if
> -finline is not used. I don't consider that acceptable for this kind of
> code. So we might have to special case Volatile!T even more in the
> compiler, to really always inline)

Not inlining in unoptimized (-O0) builds wouldn't be a problem, it could
even be useful sometimes (setting breakpoints for specific hw accesses etc).
But is that actually the case? I practically never use -O0, so you just
made me check - and indeed the GDC here *always* inlines always_inline
functions, at "-O0", even when explicitly given '-fno-inline'...

Anyway, the language *relies* on automatic inlining happening, this case
isn't special.


> Otherwise Volatile!T is OK, but it's a new, fancy idea and might need
> lots of work, whereas a volatile qualifer could be implemented easily
> and we know right now for sure that it'll work 100% as expected.

There's nothing new about it - it's how it has been done in gcc-ese, for
many, many years; it's just combining it with templates, which aren't
exactly novel either.


> Also there's effectively no increase in language complexity for users,
> as nobody will use volatile with desktop applications.

Actually, there are quite a few "normal" uses. The most obvious example
probably being communication with signal handlers. Then there are
various kinds of inter-thread/shared-mem communication schemes.


Yes, D has many problems, some of which you have mentioned in this thread. [1]
But introducing additional complexity to a language just to avoid other
problematic areas is not a good idea; that approach does not scale. The
result are many half-finished features, every one with some kind of problem.

Could a 'volatile' type qualifier be made to work, and are there technical
problems with the DIP? Yes, and No. I'm not ignoring the details; I probably
agree with most, if not all, of them.
I'm saying the DIP is a good answer, to the wrong question.

artur

[1] Which I didn't respond to, to avoid derailing the thread. ;)


More information about the Digitalmars-d mailing list