Problem with struct and property in c#

Yup, it’s absolutely right. You see, when you fetch My_va, you’re fetching a value – a copy of the current value of my_va. Changing that value would have no benefit, because you’d be immediately discarding the copy. The compiler is stopping you from writing code which doesn’t do what it looks like it does. In … Read more

How to wrap a Struct into NSObject

Hm, try to look at the NSValue at You can use it like struct aStruct { int a; int b; }; typedef struct aStruct aStruct; Then sort of “wrap” it to an NSValue object like: aStruct struct; struct.a = 0; struct.b = 0; NSValue *anObj = [NSValue value:&struct withObjCType:@encode(aStruct)]; NSArray *array = @[anObj]; To … Read more

Are structs ‘pass-by-value’?

It is important to realise that everything in C# is passed by value, unless you specify ref or out in the signature. What makes value types (and hence structs) different from reference types is that a value type is accessed directly, while a reference type is accessed via its reference. If you pass a reference … Read more

C – freeing structs

Simple answer : free(testPerson) is enough . Remember you can use free() only when you have allocated memory using malloc, calloc or realloc. In your case you have only malloced memory for testPerson so freeing that is sufficient. If you have used char * firstname , *last surName then in that case to store name … Read more

Does an unused member variable take up memory?

The golden C++ “as-if” rule1 states that, if the observable behavior of a program doesn’t depend on an unused data-member existence, the compiler is allowed to optimized it away. Does an unused member variable take up memory? No (if it is “really” unused). Now comes two questions in mind: When would the observable behavior not … Read more

What happened to the “aggregate or union type that includes one of the aforementioned types” strict aliasing rule?

The lvalue you use to access the stored value of y is not *reinterpret_cast<Foo*>(&y), of type Foo, but it is reinterpret_cast<Foo*>(&y)->x, which has the type float. Accessing a float using an lvalue of type float is fine. In C++, you can not “access the value of a union or struct” (as whole), you can only … Read more

Get attribute by name

C++ lacks built-in reflection capabilities of more dynamic languages, so you cannot do what you would like using he out of the box capabilities of the language. However, if all members are of the same type, you can do it with a map of pointers to members and a little preparation: // typedef for the … Read more