struct

Passing struct by reference causing AccessViolationException

Yet another one of my P/Invoke questions! I have this C function: int _ei_x_new(ei_x_buff* x); Essentially, it initializes a new buffer struct. In C#, I have this: [DllImport(EIDLL, EntryPoint = "_ei_x_new")] public static extern int ei_x_new(out ei_x_buff x); ei_x_buff is pretty simple: typedef struct ei_x_buff_TAG { char* bu...

How to specify maxExclusive on struct?

I want to create a structure Degrees for a GPX library. In the XSD for GPX (GPX 1.1 Schema) degreesType is defined as minInclusive = 0 and maxExclusive = 360. The structure now shall have two public static fields MinValue = 0 and MaxValue = x: public struct Degrees : IFormattable, IComparable, IComparable<Degrees>, IEquatable<Degrees> {...

When does a using-statement box its argument, when it's a struct?

I have some questions about the following code: using System; namespace ConsoleApplication2 { public struct Disposable : IDisposable { public void Dispose() { } } class Program { static void Main(string[] args) { using (Test()) { } } static Disposable Test() ...

c++ problem with enum and struct

why doesn't this compile: enum E { a, b} typedef struct { int i; E e; } S; int main(){return 0;} I get different errors on different system. ...

C# Structs - real life examples?

There are any number of questions here on SO dealing with the differences between Structs and Classes in C#, and when to use one or the other. (The one sentence answer: use structs if you need value semantics.) There are plenty of guidelines out there about how to choose one or the other, most of which boil down to: use a class unless ...

C++ creating and collecting structs in a loop

I want to create a struct from data harvested by line from a file. Each line necessitates a new struct, and the lines are accessed in a while loop. In C# I did this by creating anonymous structs and adding them to a list of structs. C++ would seem not to allow anonymous structs. I tried naming them with an incrementing variable, but this...

Smiley face when assigning improper value type to struct property!!

I am somewhat wondering if I am losing my mind, but I swear to you, this code outputs smiley faces as the .name values!! what in the world is going on? Thus far it seems to only work when the value is 1, anything else properly gives errors. I realize the code is flawed -> I do not need help with this. #include <iostream> #include <fstr...

F# : Accessing public readonly members of structs in external assemblies

I'm getting a strange error when I use F# to read a public readonly member of a struct type defined in a C# assembly. // C#: compile to Lib.dll namespace Lib { public class MyClass { public readonly int ReadonlyFoo; } public struct MyStruct { public readonly int ReadonlyFoo; public int WriteableFoo; } } ...

Compare the value of a variable at intervals

Hey I have a problem comparing the value of a CGPoint (struct with two ints: x and y) with another at certain time intervals. One is called location and has the value of where the cursor is. Every half a second or so, I want to see if it changed. How do I do this? The language is Objective-C (so C++/C stuff should work) ...

Wrapping Mutually Dependent Structs in Pyrex

Hello, I am attempting to wrap some C code in Python using Pyrex. I've run into an issue with defining two structs. In this case, the structures have been defined in terms of one another, and Pyrex cannot seem to handle the conflict. The structures look something like so: typedef struct a { b * b_pointer; } a; typedef struct b ...

What happens when you return "this" from a struct in C#?

Curious, what happens when you return keyword this from a struct in C#? For example: public struct MyStruct { // ... some constructors and properties 1-3 public MyStruct Copy() { return MyStruct(Property1, Property2, Property3); } // vs public MyStruct This() { return this; } } ...

Read double fields from structure

I´m not very experienced with C# but I urgently have to read a variable from a structure given in a library. this is the definition of the structure in the library: public struct mtLocation { public bool bAltitudeValid; public bool bCoordinatesValid; public double dAltitude; public ulong dateTime; public double dL...

Problem while porting VB.NET Code to C#

Hi, Currently I am trying to port some VB.NET code to C#. The struct looks like this in VB.NET: Public Structure sPos Dim x, y, z As Single Function getSectorY() As Single Return Math.Floor(y / 192 + 92) End Function Function getSectorX() As Single Return Math.Floor(x / 192 + 135) End Function F...

a few beginner C questions

I'm sort of learning C, I'm not a beginner to programming though, I "know" Java and python, and by the way I'm on a mac (leopard). Firstly, 1: could someone explain when to use a pointer and when not to? 2: char *fun = malloc(sizeof(char) * 4); or char fun[4]; or char *fun = "fun"; And then all but the last would set indexes 0...

Giving an instance of a class a pointer to a struct

I am trying to get SSE functionality in my vector class (I've rewritten it three times so far. :\) and I'm doing the following: #ifndef _POINT_FINAL_H_ #define _POINT_FINAL_H_ #include "math.h" namespace Vector3D { #define SSE_VERSION 3 #if SSE_VERSION >= 2 #include <emmintrin.h> // SSE2 #if SSE_VERSION >= 3 #inc...

Should I use a Struct instead of a lightweight data class for my Linq2Sql data?

I often take the classes that linq2sql generates and create a simple data-only class like so public class myentity { public Guid id { get; set; } public string name { get; set; } // etc } I don't put methods in these classes and I mainly use them as helper classes so I can serialize to/from json and other similar action...

Blindly converting structs to classes to hide the default constructor?

I read all the questions related to this topic, and they all give reasons why a default constructor on a struct is not available in C#, but I have not yet found anyone who suggests a general course of action when confronted with this situation. The obvious solution is to simply convert the struct to a class and deal with the consequence...

Need way to alter common fields in different structs.

I'm programming in C here, for Windows and various Unix platforms. I have a set of structs that have common fields, but also fields that are different. For example: typedef struct { char street[10]; char city[10]; char lat[10]; char long[10]; } ADDR_A; typedef struct { char street[10]; char city[10]; char z...

Xaml serialization and immutable structs?

How can I do this? Tried using a TypeConverter, but the only thing I could think of was to construct the XML for the types, which doesn't quite cut it. TypeConverters in xaml serialization will escape xml and treat it like plain text. Value converters aren't much better. Now, I'm moving to ISupportInitialize and will throw if changes...

What is happening here? How can I call the default constructor when there is none?

Given the following code: public struct Foo { public Foo(int bar, int baz) : this() { Bar = bar; // Err 1, 2 Baz = baz; // Err 3 } public int Bar { get; private set; } public int Baz { get; private set; } } What does : this() actually do? There is no default constructor, so what is it calling? With...