DMD hackers: pragma(address): Is this possible?

Johannes Pfau via Digitalmars-d digitalmars-d at puremagic.com
Tue Nov 25 06:08:28 PST 2014


Am Wed, 26 Nov 2014 00:28:52 +1100
schrieb "Daniel Murphy" <yebbliesnospam at gmail.com>:

> "Johannes Pfau"  wrote in message news:m51upj$u2v$1 at digitalmars.com...
> 
> > But does this really make sense? What makes a variable a variable?
> > For example the GCC backends has builtin support for extern,
> > static, const, manifest variables, but no way to specify an address
> > for an extern variable. Is there a reason for this?
> 
> Makes sense to me.   I image gcc backends don't natively support this 
> because it's equivalent to casting to a pointer and dereferencing.
> 
> Do we really need it with ref return and force-inline?
> 
> pragma(always_inline)
> ref ubyte PORTB() @property { return *cast(ubyte*)0x1000; }
> 
> That should also result in optimal asm, right? 
> 

Good idea, this works and results in equal ASM. A minor drawback is
that this emits an additional function (even with always inline), but
that's a problem that also occurs in other contexts and I've got a
workaround for that.

Inlining in GDC right now only works across modules when templates are
used. Templating the PORTB property doesn't work (PORTB()() is not an
lvalue when taking the address &PORTB).
So I'll probably have to implement cross-module inlining then.



More information about the Digitalmars-d mailing list