struct

Will adding data members(At end) in Exportable struct cause problems ?

Exportable function has the struct as a one of the parameter. This dll is used by many Exes One of the Exe needs to send some additional data , so we have added one member at the end of the struct and distributed the dll. Now my question is, if we put the new dll in other Exes which is not aware of the Extra member cause problems ? ...

How to access members of a `struct' according to a variable integer in C?

Suppose I have this struct (which incidentally contain bit-fields, but you shouldn't care): struct Element { unsigned int a1 : 1; unsigned int a2 : 1; ... unsigned int an : 1; }; and I want to access the i'th member in a convenient way. Let's examine a retrieval solution. I came up with this function: int getval(str...

How do I convert an array of structs into an array of Point3D objects in C#?

Hi All, I intend to form 3D mesh object. The mesh object has an 3D point array of approx. 50.000 items. Due to the number of 3D points, the array must be initialized on the heap. The required code is, shortly, as follows: class MyMesh { public MeshGeometry3D Mesh3D // Properties tanimlaniyor { get { return GetMesh3D(); }...

C: Recommended style for dynamically sized structs

I need to transfer packets through the internet whose length should be dynamic. struct packet { int id; int filename_len; char filename[]; }; The problem is that zero-length arrays are not ISO-compliant. Should I use char filename[1]; instead? But then sizeof(struct packet) will not return the correct value anymore. ...

Overhead of using this on structs

When you have automatic properties, C# compiler asks you to call the this constructor on any constructor you have, to make sure everything is initialized before you access them. If you don't use automatic properties, but simply declare the values, you can avoid using the this constructor. What's the overhead of using this on constructo...

How to create a const member for an immutable type?

If you have an immutable type like this: struct Point3 { } and a member inside like origin: public static const Point3 Origin = new Point3 (0,0,0); should you use: new Point3 (0,0,0) ? It seems to me that since the type can not be changed, why have many origins that are essentially the same thing? Like we never change 0, right...

How can I remove the VS warning C4091: 'typedef ' : ignored on left of 'SPREADSHEET' when no variable is declared

This warning is triggered multiple times in my code by the same declaration, which reads : // Spreadsheet structure typedef struct SPREADSHEET { int ID; // ID of the spreadsheet UINT nLines; // Number of lines void CopyFrom(const SPREADSHEET* src) { ID = src->ID; ...

C++: syntax for accessing member struct from pointer to class

I'm trying to access a member structs variables, but I can't seem to get the syntax right. The two compile errors pr. access are: error C2274: 'function-style cast' : illegal as right side of '.' operator error C2228: left of '.otherdata' must have class/struct/union I have tried various changes, but none successful. #include <iostream...

Can a C++ compiler re-order elements in a struct

Hi All, Can a C++ compiler (specifically g++) re-order the internal elements of a struct? I'm seeing some strange behaviour where I have a structure that contains something like the following: Struct SomeStruct{ ... ... long someLong; long someLongArray[25]; unsigned long someUnsignedLong; unsigned long someUnsignedL...

What's the point of this pattern: using a struct to contain a single method

In our code we have quite a few cases of this pattern: class outerClass { struct innerStruct { wstring operator()( wstring value ) { //do something return value; } }; void doThing() { wstring initialValue; wstring finalValue = innerStruct()( initialValu...

JNA Passing Structure By Reference Help

Hi all, I'm trying to use JNA to talk over a USB device plugged into the computer. Using Java and a .dll that was provided to me. I am having trouble with the Write function: C code: typedef struct { unsigned int id; unsigned int timestamp; unsigned char flags; unsigned char len; unsigned char data[16]; } CANMsg; ...

Recursively freeing C structs

I have a struct that only contains pointers to memory that I've allocated. Is there a way to recursively free each element that is a pointer rather than calling free on each one? For example, let's say I have this layout: typedef struct { ... } vertex; typedef struct { ... } normal; typedef struct { ... } texture_coord; typedef struct...

Is it good practice to encapsulate many parameters that are alike into a struct

Basically, I have something like the following: public string SomeDBMethod(string server, string dbName, string userName, string password,...) Is it good practice to refactor it to the following: public string SomeDbMethod(DBParams parameters, ...) Where DBParams is defined as follows: public struct DBParams { string Server {get...

C Prog.: Structure as argument of function!?

I am trying to to create structure "Date of birth", and function that will assign values to the structure, and i am wondering is that possible to do that somehow like this: (PS. I am constantly getting error "Argument list syntax error", for 2nd and 23th lines.) #include <stdio.h> void input (dob_st *); int main () { typedef struct...

How to transfer a variable from a struct to a method ?

Hi All, Let's assume we have an array named "points" having the type of Point3D in a struct and want to use these points in a method. How to transfer from the struct to the method ? The following are from the code snippet. Regards Cemil public MeshGeometry3D GetMesh3D() { **(just here, we want to use the 3D points coming from the G...

Union and struct packing problem

Hi, I'm writing some software where each bit must be exact(it's for the CPU) so __packed is very important. typedef union{ uint32_t raw; struct{ unsigned int present:1; unsigned int rw:1; unsigned int user:1; unsigned int dirty:1; unsigned int free:7; unsigned int frame:20; } __packed; }__packed page_union_t; that is my structu...

Difference in declaring structures

Hello, I was using my structure like this. I don't like to typedef as I have told it can hide errors. However, I was looking at some sample code and I have seen structures declared like this. And this is the normal way I declare them. struct person { int age; char name[32]; }; using like this: struct person person_a; ...

In C, how do you declare the members of a structure as volatile?

How do you declare a particular member of a struct as volatile? ...

C# - Value Type Equals method - why does the compiler use reflection ?

I just came across something pretty weird to me : when you use the Equals() method on a value type (and if this method has not been overriden, of course) you get something very very slow -- fields are compared one to one using reflection ! As in : public struct MyStruct{ int i; } (...) MyStruct s, t; s.i = 0; t.i = 1; ...

Marshal Unmanaged struct to managed code using c#

Hi experts, I need to process the bytes[] when i get from external application. The external application is also done in c# and they send the bytes thru UDP. They are sending the bytes converted from struct which is stated below : public struct DISPATCH_MESSAGE { [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] public c...