struct

How can I simulate a C++ union in C#?

I have a small question about structures with the LayoutKind.Explicit attribute set. I declared the struct as you can see, with a fieldTotal with 64 bits, being fieldFirst the first 32 bytes and fieldSecond the last 32 bytes. After setting both fieldfirst and fieldSecond to Int32.MaxValue, I'd expect fieldTotal to be Int64.MaxValue, whic...

Accessing vectors of structs

I have a struct: struct OutputStore { int myINT; string mySTRING; } If I create an array of type OutputStore as follows: OutputStore *OutputFileData = new OutputStore[100]; then I can address it with: OutputFileData[5].myINT = 27; But if I use a vector instead of an array: vector<OutputStore> *OutputFileData = new vect...

What is the difference when using typdef when declaring a stuct c++?

Possible Duplicates: Why should we typedef a struct so often in C? Difference between struct and typedef struct in C++? What is the difference between the following type declarations? struct Person { int age; }; typedef struct { int age; }Person; I understand that struct { int age; }Person; Creates and ...

lists in structs in F# ?

Hi I'm very new to F# and I'm trying to make a struct for storing polygons, and it has to contain a list of coordinates: type Polygon = struct val Coords : list new(list_of_Coords) = { Coords = list_of_Coords } end but Visual studio says "The type 'Microsoft.FSharp.Collections.list<_>' expects 1 type argument(...

Immutable struct with collection

I'm making an immutable struct in .Net which contains a read only collection of a different immutable struct (I have full control over the entire design). I don't need a non-mutating Add method. What's the best way to do that? I could make the outer struct have a reference to a ReadOnlyCollection containing the inner struct. Are ther...

How do I ignore a field size in a struct using Marshal.SizeOf?

Is there a way to ignore a field in the calculated of the struct size using Marshal.SizeOf Ex: public struct Message { public ushort X; public ushort Y; // Ignore this field in the calculation } int size = Marshal.SizeOf(typeof(Message)); Right now size is 4. I want the size to be 2. Is there a way to do this? ...

Struct for depth-curves in sea-maps

I'm trying to make a struct in F# for representing depth curves in a sea map. It has to contain a list of coordinates and a float telling what depth is represented (eg. "4.5 meters"). I have made it this way: type Coord = struct val X : float val Y : float new(x,y) = { X = x ; Y = y } end type DepthCurve...

Ruby: Struct vs OpenStruct

In general, what are the advantages and disadvantages of using an OpenStruct as compared to a Struct? What type of general use cases would fit each of these? ...

Exposing C# struct to COM breaks for VB6 app

Last Updated: 2009-08-11 2:30pm EDT A few days ago I posted this question about some very strange problems. Well, I figured out what specifically was causing a build on one machine to not run on others and even came up with a work-around, but now it leaves me with a nice, specific question: Why? To reproduce the problem, I create a new...

Structure prototype?

How do I put a struct in a separate file? I can do it with functions by putting the function prototype in a header file e.g. file.h and the function body in a file like file.cpp and then using the include directive #include "file.h" in the source file with main. Can anybody give a simple example of doing the same thing with a structure l...

Sizes of structs on 32 bit and 64 bit

In the .NET struct design guidelines, it gives the maximum sensible size of a struct as 16 bytes. How do you determine how large your struct is, and is it affected by the architecture your program is running on? Is this value 32-bit only, or for both archs? ...

C# struct initialization with compile error but runs correctly

Inside XNA struct Vector2 are two public variables X and Y. I have the following code: Vector2 v; if(b) v.X=1; else v.Y=2; //use v The compiler gives "Use of unassigned local variable 'v'" But it runs correctly nonetheless. Is there a more correct way of doing it? ...

c struct grabbing data by offset

Lets say I have this struct: typedef struct nKey { int num; widget* widget; } NUMBER_KEY; and a function: void dialKey(widget* widget) { // Need to print 'num' of the struct that this widget resides in } How do I go about accomplishing this? I tried something like: printf("%d", * (int *) widget - sizeof(int)); // F...

Structs With Constraints

I've had a hard time figuring out how I can write a struct in C# that has constraints on its fields' values. For example, System.DateTime DateTime d = new DateTime(); puts the value 01/01/0001 12:00:00 AM in d. But I can't write an explicit parameterless constructor, as structs are not allowed to have an explicit parameterless const...

Why don't structs support inheritance?

I know that structs in .NET do not support inheritance, but its not exactly clear why they are limited in this way. What technical reason prevents structs from inheriting from other structs? ...

How to create a structure with two variable sized arrays in C

I am writing a light weight serialization function and need to include two variable sized arrays within this. How should I track the size of each? How should I define the struct? Am I going about this all wrong? EDIT: the result must be a contiguous block of memory ...

Why can TimeSpan and Guid Structs be compared to null?

I've noticed that some .NET structs can be compared to null. For example: TimeSpan y = new TimeSpan(); if (y == null) return; will compile just fine (the same with the Guid struct). Now I know that stucts are value type and that the code above should not compile, unless there's an overload of operator == which ta...

Sending structure using recvfrom() and sendto()

I am using C language which is a common platform for both the server and the client. I have a structure of a particular type which I want to send to the client from the server. For e.g. SERVER CODE //necessary declarations struct hostent *hp; hp=gethostbyname("www.google.com"); sendto(sockDes,&hp,sizeof(hp),0,(struct sockaddr *)&...

std::sort and binary '=' operator issue with a C++ struct

Ok... I have this struct and comparison function- struct Edge { char point1; char point2; int weight; bool operator<( const Edge& rhs ) const { return( weight < rhs.weight ); } }; //end Edge bool compareEdge( const Edge& lhs, const Edge& rhs ) { return...

read from file to array of structs within structs in C++

I have asked this question previously here and a similar question was closed. SO based on a comment from another user, I have reframed my question: In the first post, I was trying to read tha data from a file into an array with a struct.By using indata << p[i] and is >> p.fId, I was able to read values from data file into PersonId. No...