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 https://developer.apple.com/documentation/foundation/nsvalue 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

How to filter a vector of custom structs?

It’s very important programming skill to learn how to create a minimal, reproducible example. Your problem can be reduced to this: struct Vocabulary; fn main() { let numbers = vec![Vocabulary]; let other_numbers: Vec<Vocabulary> = numbers.iter().collect(); } Let’s look at the error message for your case: error[E0277]: a collection of type `std::vec::Vec<Vocabulary>` cannot be built from … Read more

Variable Sized Struct C++

Some thoughts on what you’re doing: Using the C-style variable length struct idiom allows you to perform one free store allocation per packet, which is half as many as would be required if struct Packet contained a std::vector. If you are allocating a very large number of packets, then performing half as many free store … Read more

How can I malloc a struct array inside a function? Code works otherwise

Function arguments are passed by value in C and modifying arguments in callee won’t affect caller’s local variables. Use pointers to modify caller’s local variables. void CreateMap(MapTileData ***Map, int xSize, int ySize) { //Variables int i; //Allocate Initial Space *Map = calloc(xSize, sizeof(MapTileData)); for(i = 0; i < xSize; i++) { (*Map)[i] = calloc(ySize, sizeof(MapTileData)); … Read more

Iterating over same type struct members in C

Most of the attempts using a union with an array are prone to failure. They stand a decent chance of working as long as you only use int’s, but for other, especially smaller, types, they’re likely to fail fairly frequently because the compiler can (and especially with smaller types often will) add padding between members … Read more