struct

MPI and C structs

I have to admit, I was quite shocked to see how many lines of code are required to transfer one C struct with MPI. Under what circumstances will it work to simply transmit a struct using the predefined dataype MPI_CHAR? Consider the following example: struct particle { double x; double y; long i; }; struct particle p; MPI_...

Go - Access to another struct by value or by pointer

What difference there is when you access to another struct by value or by a pointer? When should be used each one of them? type foo_ struct { st uint8 nd uint8 } type bar struct { rd uint8 foo foo_ } type barP struct { rd uint8 foo *foo_ } ...

Clean bindings with structs

I have a model class for which it makes quite a lot of sense to have NSSize and NSPoint instance variables. This is lovely. I'm trying to create an editing interface for this object. I'd like to bind to size.width and whatnot. This, of course, doesn't work. What's the cleanest, most Cocoa-y solution to this problem? Of course I could w...

Convert a byte array to a class containing a byte array in C#

I've got a C# function that converts a byte array to a class, given it's type: IntPtr buffer = Marshal.AllocHGlobal(rawsize); Marshal.Copy(data, 0, buffer, rawsize); object result = Marshal.PtrToStructure(buffer, type); Marshal.FreeHGlobal(buffer); I use sequential structs: [StructLayout(LayoutKind.Sequential)] public new class Packe...

How do I cast a void pointer to a struct in C?

In a project I'm writing code for, I have a void pointer, "implementation", which is a member of a "Hash_map" struct, and points to an "Array_hash_map" struct. The concepts behind this project are not very realistic, but bear with me. The specifications of the project ask that I cast the void pointer "implementation" to an "Array_hash_ma...

how to search a string in structure variable ( C# )

public struct Items { public string Id; public string Name; } public Items[] _items = null; if (_items.Contains("Table")) { // i need to check the structure and need to return correponding id } and am having a list of variables in my structure variable... i need to sea...

Reading file and populating struct

Hi, I have a structure with the following definition: typedef struct myStruct{ int a; char* c; int f; } OBJECT; I am able to populate this object and write it to a file. However I am not able to read the char* c value in it...while trying to read it, it gives me a segmentation fault error. Is there anything wrong with my ...

For structs, do I have to call the constructor explicitly in C#?

The question is about the structs. When I declare a struct type variable/object (don't know which one suits better) or an array or list of structs, do I have to call the constructor explicitly like objects or just declaring will suffice like variables? ...

Clone existing structs with different alignment in Visual C++

Is there a way to clone an existing struct with different member alignment in Visual C++? Here is the background: I use an 3rd-party library, which defines several structs. To fill up the structs, I pass the address of the struct instances to some functions. Unfortunately, the functions only returns unaligned buffer, so that data of so...

How do i fix this code? C# Ptr to a struct

As you may know, the wall rect will not update since its a copy and not a reference. Is there a way for me to make a reference or pointer to r and not change this code? I suppose i could do a find/replace in the function but that something i try not to do. //code to get wall var r = wall.r; //more code r.Height += yDif; ...

C++ increment operator

How to differentiate between overloading the 2 versions of operator ++ ? const T& operator ++(const T& rhs) which one? i++; ++i; ...

struct size is different from typedef version?

I have the following struct declaration and typedef in my code: struct blockHeaderStruct { bool allocated; unsigned int length; }; typedef struct blockHeaderStruct blockHeader; When I do sizeof(blockheader), I get the value of 4 bytes back, but when I do sizeof(blockHeaderStruct), I get 8 bytes. Why is this happening? Why am ...

How to fix the size of the <html:select> combo box (contents may be larger but the combo size should be fixed).

Hello all , How to fix the size of the combo box (contents may be larger but the combo size should be fixed).Now my combo size is changed based on the items in the combo. I'm trying to get something similar to the yahoo sign up page security Question combo: https://edit.yahoo.com/registration?.src=fpctx&amp;.intl=in&amp;.done=http://i...

C++: why a self pointer of a struct automatically changes to void*

struct ptr{ int node; ptr *next; ptr(){} ptr(int _node, ptr *_next){ node=_node; next=_next; } }; struct list_t{ ptr *sht; int size; void push(int node){ size++; sht=new ptr(node,sht); } }shthead[100001], comp[200001], tree[200001]; The struct ptr is a smart pointer, be used as a linked l...

C# Strange Behavior

I have a custom struct : struct A { public int y; } a custom class with empty constuctor: class B { public A a; public B() { } } and here is the main: static void Main(string[] args) { B b = new B(); b.a.y = 5;//No runtime errors! Console.WriteLine(b.a.y); } When I run the above program, it does ...

Use Struct as a Ptr/class? Need a fix .NET

I wrote a bunch of code and i would like to fix it the fastest way possible. I'll describe my problem in a easier way. I have apples and oranges, they are both Point and in the list apples, oranges. I create a PictureBox and draw the apple/oranges on screen and move them around and update the Point via Tag. The problem now is since its...

a nicer way to create structs in a loop

Hi guys, I haven't coded in C++ in ages. And recently, I'm trying to work on something involving structs. Like this typedef struct{ int x; int y; } Point; Then in a loop, I'm trying to create new structs and put pointers to them them in a list. Point* p; int i, j; while (condition){ // compute values for i and j with som...

How to initialise a struct-type in the initialisation list?

How can I initilise a structure in the constructor list? Say: struct St{int x, y}; class Foo { public: Foo(int a = 0, int b = 0) : /*here initilise st_foo out of a and b*/ {} private: const St st_foo; }; ...

Iterating through struct fieldnames in MATLAB.

My question is easily summarized as: "Why does the following not work?" teststruct = struct('a',3,'b',5,'c',9) fields = fieldnames(teststruct) for i=1:numel(fields) fields(i) teststruct.(fields(i)) end output: ans = 'a' ??? Argument to dynamic structure reference must evaluate to a valid field name. Especially since teststru...

Multiple Linked List in C

I have a problem about Linked Lists. I already know how to create structures and linked list. But now I have to create arbitrary number of linked list which are also be kept in another structure. Which means : struct list{int x, struct list *next; }; struct parent{int x, struct list *head, struct parent *next;} And after lists are...