When accessing a member of some class, I can use e.g.:
this->myVar = 10
or I can just write:
myVar = 10
I like to use this->
because it explicitly declares that the variable is a member of this class, but does it cause any overhead in comparison to just using the variable name by itself?
As an alternative I could maybe add a unique prefix to the vars, such as _TmyVar
, but I've been using this->
for a long time so I just wondered.
No. The size of all the types in the struct , and thus the offset to each member from the beginning of the struct , is known at compile-time, so the address used to fetch the values in the struct is every bit as knowable as the addresses of individual variables.
Show activity on this post. No. Struct does not add any size, or have any overhead in the compiled C. It is a layer of syntax that requires additional work by the compiler, but has no overhead at runtime.
There is no overhead. The compiler will generate the exact same code for both versions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With