alias of member from pointer to struct?

BCS ao at pathlink.com
Sun Apr 15 14:35:55 PDT 2007


Reply to Jarrett,

> "BCS" <ao at pathlink.com> wrote in message
> news:ce0a334394148c94cbf4314a4da at news.digitalmars.com...
> 
>> Reply to Jarrett,
>> 
>>> If the static if is not at global scope, you can make a variable
>>> that points to the member:
>>> 
>>> const bool pick = false;
>>> 
>>> struct S
>>> {
>>> int i;
>>> int j;
>>> }
>>> void main()
>>> {
>>> S* s;
>>> static if(pick)
>>> int* var = &s.i;
>>> else
>>> int* var = &s.j;
>>> }
>> That's what I'm trying to avoid. :(
>> 
> If you want to avoid the address calculation every time you write
> "s.i" or "s.j", that's what you'll have to do.  Even a macro that
> expanded to "s.i" or "s.j" would not give you any performance gain.
> 

In this particular case the issue is that I want to be totally sure that 
exactly the same thing os done for each version and avoid the extra copy. 
Come to think of it though, it will probably get optimized to the extra variable 
version anyway. Oh well, I guess I can live with it.




More information about the Digitalmars-d-learn mailing list