structs

sending structs over sockets

Hi, i am using vb.net and i would to send some structs to a C++ tcp server. The problem is the structs i am sending might contain other structs. Struct{ uint length; byte really; customStruct customStuff; }FirstStruct; Struct{ uint length; char[] name; }CustomStruct; Lets say i want to send FirstStruct over to the C++...

C++ How to loop through a list of structs and access their properties

I know I can loop through a list of strings like this: list<string>::iterator Iterator; for(Iterator = AllData.begin(); Iterator != AllData.end(); Iterator++) { cout << "\t" + *Iterator + "\n"; } but how can I do something like this? list<CollectedData>::iterator Iterator; for(Iterator = AllData.begin(); Iterator != ...

Understanding XML-RPC param possibilities, especially recursion of values

One thing I've noticed with all the XML-RPC examples out there, including the spec itself, is there is no detailed example of a schema using recursive (param) values. It is hard to understand what should actually be possible within XML-RPC without these illustrations, and I wonder if someone could help me get a better handle on it. The ...

Handling input into struct elements with array

I'm doing an assignment that involves structs. You are to make a struct with three variables and declare 3 instances of that struct. The program will then ask for the user to input 9 pieces of information. I don't like having to type cout and cin unnecessarily (9 sequential times?), so I was thinking I could use loops to handle the inpu...

typedefs of structs not seeming to go through in header files?

I'm having some trouble with some struct typedef declarations in a header file not seeming to go through to my implementation file. Specifically, I have the following types defined: Type, Value, Integer, String, and Float. They are all typedef'd from struct names, in the exact same manner. I'm writing an informal hashCode function to su...

C initialize array within structure

I want to have an variable-length array contained within a structure, but am having trouble initializing it correctly. struct Grid { int rows; int cols; int grid[]; } int main() { struct Grid testgrid = {1, 3, {4, 5, 6}}; } Everything I try gives me an 'error: non-static initialization of a flexible array member' error. ...

arrays of structs need advice

I made an array of structs to represent map data that gets drawn; however I didn't double check it till it was too late: when I load in a new map I get either an "out of memory exception" (if i try to make a new array struct first) or I get a screwed up map that would require a lot of recodeing to get it to work right (if i just initiali...

c++: Initialize struct with one array containing all arguments

Hi, I am currently working on a small tokenizer template function which also casts the tokens to different objects. this works really nice aslong as all the strucs I cast to have the same number of items. what I would like to do know is to make the function cast to structs with any number of items. The bottleneck of the function for me ...

Copying arrays of structs in C

Hi there, It's been a long since I don't use C language, and this is driving me crazy. I have an array of structs, and I need to create a function which will copy one array to another (I need an exact copy), but I don't know how to define the function call. I guess I need to use pointers, but when I try it gives me an error. struct gro...

C struct problem

I am a C beginner, and I am curious why this gives me a Seg Fault everytime: #include <stdio.h> #include <stdlib.h> struct Wrapper { int value; }; int main () { struct Wrapper *test; test->value = 5; return 0; } I know I don't fully understand pointers yet, but I thought that struct_ptr->field is the same as (*struc...

data types and structs in C#

I've been using "Int32", "String", and "Boolean" instead of "int", "string", "bool" in C# for a while now, but I don't know why. Why does this matter? Which is "better"? What's the difference? I have used Int32? because it is nullable in my ORM for my database, so there is that. ...

double pointer and structures

Hi. I'm pretty sure I'm doing nothing wrong, but thought I'd ask anyway. We have: struct some_struct **array_of_ptrs = calloc (num, sizeof (struct some_struct*)); Now assume I just point each of these pointers in the 'array' to a struct some_struct. Now surely to free up the memory, I just do: free (array_of_ptrs); Surely this is...

Shoud I use LayoutKind.Auto for my structs if they don't perform in COM Interop?

By default structs in C# are implemented with [StructLayout( LayoutKind.Sequential )] for reasons basically stating that these type of objects are commonly used for COM Interop and their fields must stay in the order they were defined. Classes have LayoutKind.Auto defined. My question is should I explicitly state my structs as [StructLa...

C#: Are struct members more performant?

On a blog entry, Luca Bolognese ponders this idea about structs vs. classes as member fields: The reason to use a struct is to not allocate an additional object on the stack. This allows this solution to be as 'performant' as simply having coded the fields on the class itself. Or at least I think so ... How accurate is th...

How do we change a struct value that has been passed in a method?

I want to pass a struct within a method so i can change it's value within, but I am not too sure on it's syntax: struct qsTracker { int points; BOOL flagged; } myCurrentQs; [self calculateScore:myCurentQs]; -(void) calculateScore:(struct qsTracker) currentQs { currentQs.points++; currentQS.flagged = YES;...

Problem with reading data into structs using a C casting method

Hi, I'm writing an MD3 model loader in C++ and I understand the file format and what I need to do but I can't seem to get the syntax right. I have a class for the model and within that class there are a set of structs which will have the model data read into them. In the implementation of the class there is a constructor which reads da...

Comparing structs to null

Possible Duplicate: C# okay with comparing value types to null I was working on a windows app in a multithreaded environment and would sometimes get the exception "Invoke or BeginInvoke cannot be called on a control until the window handle has been created." So I figured that I'd just add this line of code: if(this.Handle != nu...

[C++] Overlaying a struct onto a u_char pointer.

My professor has instructed me that we can lay a struct over (casting) the pointer in memory we are getting in order to more easily interpret the data. I asked about this in class today and this is what he said would work. This is not compiling complaining about how it can't cast it. What am I doing wrong? I am about to resort to parsi...

C# Structs: Unassigned local variable?

From the documentation: Unlike classes, structs can be instantiated without using a new operator. So why am I getting this error: Use of unassigned local variable 'x' When I try to do this? Vec2 x; x.X = det * (a22 * b.X - a12 * b.Y); x.Y = det * (a11 * b.Y - a21 * b.X); Where Vec2 x is a struct? ...

Access a value from a struct via a pointer? (C++)

Here is my struct: struct Checker { short row; short col; unsigned short number; short color; }; Now, I have to also make another struct to represent a checkers board: struct Board { Checker checkers[2][13]; // Zeroth entry of 13 is not used. Checker *grid[8][8]; // each entry holds Null or an address ...