struct

C# - Passing struct from one object to another

Hi. I'm trying to pass a struct from one object to another. I have the following code: private void mainMenuStripNewProject_Click(object sender, EventArgs e) { frmNewProject frmNewProject = new frmNewProject(this); if (frmNewProject.ShowDialog() == DialogResult.OK) { StructProjectSettings tem...

How to properly define a function pointer in struct, which takes struct as a pointer?

I have a struct with a callback function, the callback function needs a pointer to the structure in order to do its operation. How do I properly define these elements such that is will compile without warnings? typedef struct { // some fields required for processing... int (*doAction)(struct pr_PendingResponseItem *pr); } pr_P...

Typedef struct question

Why would I want to do this? typedef struct Frame_s { int x; int y; int z; } Frame_t; Also if I want to create an object what do I use Frame_s or Frame_t? ...

So now struct can have virtual function and support inheritance ? What difference with classes then ? What the true purpose of information hiding ?

Possible Duplicate: What are the differences between struct and class in C++ http://www.cplusplus.com/reference/std/typeinfo/type_info/ I guess my "teacher" didn't tell me a lot about the differences between struct and classes in C++. I read in some other question that concerning inheritance, struct are public by default... ...

Structures and casting in C

I was wondering: If I have structure definitions, for example, like this: struct Base { int foo; }; struct Derived { int foo; // int foo is common for both definitions char *bar; }; can I do something like this? void foobar(void *ptr) { ((struct Base *)ptr)->foo = 1; } struct Derived s; foobar(&s); e. g. cast the void p...

sizeof empty structure is 0 in C and 1 in C++ why?

Possible Duplicates: Empty class in C++ What is the size of an empty struct in C? I read somewhere that size of an empty struct in C++ is 1. So I thought of verifying it. Unfortunately I saved it as a C file and used <stdio.h> header and I was surprised to see the output. It was 0. That means struct Empty { }; int main(v...

Any reason to prefer memset/ZeroMemory to value initialization for WinAPI structs?

In Win32 programming a handful of POD structs is used. Those structs often need to be zeroed out before usage. This can be done by calling memset()/ZeroMemory() STRUCT theStruct; ZeroMemory( &theStruct, sizeof( theStruct ) ); or by value initialization: STRUCT theStruct = {}; Although the two variants above are not equivalent in g...

Why is struct slower than float ?

If I have array of structs MyStruct[]: struct MyStruct { float x; float y; } And it's slower than if I do float[] -> x = > i; y => i + 1 (so this array is 2x bigger than with structs). Time difference for 10,000 items compare each other (two fors inside) : struct 500ms, array with only floats - 78ms I thought, that struct a...

Compound literals in MSVC

In GCC, I'm able to do this: (CachedPath){ino} inode->data = (struct Data)DATA_INIT; where: struct CachedPath { Ino ino; }; typedef int8_t Depth; struct Data { Offset size; Blkno root; Depth depth; }; #define DATA_INIT {0, -1, 0} MSVC gives the following error for these kind of casts: error C2143: syntax error : m...

lookup table in c

Hi, I'm creating a lookup table in C When I define this: typedef struct { char* action; char* message; } lookuptab; lookuptab tab[] = { {"aa","bb"}, {"cc","dd"} }; it compiles without errors but when I do something like this: typedef struct { char* action; char* message[]; } lookuptab; lookuptab tab[] = { {"aaa", {"bbbb"...

c structure problem

Hi everybody, thanks for your support for solving my previous problems. Now I'm studying self referential structures. I have written the following code: #include <stdio.h> int main() { system("clear"); struct node { int x; struct node *next; } p1; printf(" \nthe address of node1 = %u",& p1); printf(" \n\nthe size of node 1 = %d",...

Typedef of structs

I am using structs in my project in this way: typedef struct { int str1_val1; int str1_val2; } struct1; and typedef struct { int str2_val1; int str2_val2; struct1* str2_val3; } struct2; Is it possible that I hack this definition in a way, that I would use only types with my code, like struct2* a; a = (struct2*...

C++ Struct in array, help!

Hello - I have an iPhone app that used to use an array of several thousand small objects for its data source. Now, I am trying to make it use C++ Structs, to improve performance. I have written the struct, and put it in "Particle.h": typedef struct{ double changeX; double changeY; double x; double y; }ParticleStruct; The...

Matlab variable type help

How to convert variable of 'struct' type to a matrix in Matlab? How do we convert the q_yearly_w, in the code below, which is of type 'struct' to a matrix with which we can perform normal mathematical operations? %# open the file fid = fopen(Reportq_rwo); %# read it into one big array, row by row fileContents = textscan(fid,'%s','Deli...

Declare class member at runtime in D

I want the following struct as a class member, but I don't know the type of T, so I need "declare" the struct at runtime. struct Chunk (T) { string id; T[][] data; } class FileBla { this() { Chunk !int ck; // need to be turned in a class member } } Should be missing something easy. ...

"no base classes of the same type as the first non-static data member"

I asked this a while ago on comp.std.c++ and got no reply. I'm just going to quote my post there with little modification. Is the last requirement of standard-layout classes, 9/6, necessary or useful? A footnote explanation is provided: This ensures that two subobjects that have the same class type and that belong to the sa...

Multi-Attribute Sorting and Filtering on an Array of Structs

I have an array of structs. Each struct has the following two attributes: win % # of wins I want to sort the array of structs by win %; however, for only those structs with at least 3 wins. Any suggestions? ...

What's the point of this series of C typedef/struct/union/enum definitions?

Inside of this first step towards a bootstrapped scheme interpreter I find the following set of typedef, struct, union, and enum definitions: typedef enum {FIXNUM} object_type; typedef struct object { object_type type; union { struct { long value; } fixnum; } data; } object; In particular, I'm ...

Referencing a typedef as its struct counterpart.

Ok guys, we all know there are all lot of typedef/struct questions out there, but I feel this one is a bit of a mind bender. I'm simulating the neighbor interactions of a crystal lattice using strictly C. I have a struct called "ball_struct" which I typedef'ed as just "ball". The struct contains a pointer to a list of ball_structs (sin...

Initialsing Array of Structs in C

Hi, I'm looking to initialize a global array of stucts in C within the header file however it keeps complaining when compiling. Here's my struct typedef struct { char input[100][100]; int count; char name; }INPUT; extern INPUT[] global; Thanks ...