Could someone explain this line:

In more complicated contexts, such as "+=", a rewrite is performed by doing both get and put.

Taken from: MSDN - Property

What do they mean by rewrite?Is it a compile-time rewrite or does it induce run-time overhead?As far as I know in release mode properties are compiled to the same thing, so they must have the same performance as getters/setters, right?

  • I'm not sure what your question is. If += means what I think it means, it performs a get to get the original value, adds 1 to it, and then performs a put to write the new value, which is what I assume they mean by rewriting the value. Jan 6, 2014 at 21:55
  • @RobertHarvey so with optimizations it compiles to the same ASM code as having the value as public, right?
    – ulak blade
    Jan 6, 2014 at 22:02
  • No, I don't think so. Read the description at the top of the page, which states: "The compiler treats these 'virtual data members' as data members by changing their references into function calls." Jan 6, 2014 at 22:07
  • I think it's referring to the possiblity of using it with virtual methods as get and set parameters in the property.
    – ulak blade
    Jan 6, 2014 at 23:13
  • It still means an additional level of indirection. Accessing a property via its getter or setter is not at all the same thing as accessing a public member variable directly. Jan 6, 2014 at 23:16

1 Answer 1


As you see in complete paragraph in MSDN page to that you referred, all work is done by compiler.

When the compiler sees a data member declared with this attribute on the right of a member-selection operator ("." or "->"), it converts the operation to a get or put function, depending on whether such an expression is an l-value or an r-value. In more complicated contexts, such as "+=", a rewrite is performed by doing both get and put.

By then it means that following line:

s.the_prop = 5;
n = s.the_prop;

compiled to:

n = getprop();

A complicated case like:

s.the_prop += 5;

compiled to:

s.putprop(s.getprop() + 5);

I think it is not as complicated as they said in MSDN!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.