structs

Cocoa structs and NSMutableArray

I have an NSMutableArray that I'm trying to store and access some structs. How do I do this? 'addObject' gives me an error saying "Incompatible type for argument 1 of addObject". Here is an example ('in' is a NSFileHandle, 'array' is the NSMutableArray): //Write points for(int i=0; i<5; i++) { struct Point p; buff = [in readD...

C++ struct definition

Possible Duplicate: What does unsigned temp:3 means I just found this code in a book (was used in an example) typedef struct { unsigned int A:1; unsigned int B:1; unsigned int C:1; } Stage; What is the meaning of this structure definition? (the A:1;) ...

Please help - sorting integers in structs

I have a struct like this: struct db { string name,sur; int num; }; And declared an array of db structs: struct db a[10]; and every member of a[] is filled with a name, surname and a number but there can be the same number appearing multiple times. I need to sort the numbers, and print the results, i.e. sort by the num of each s...

Structs, Interfaces and Boxing

Take this code: interface ISomeInterface { public int SomeProperty { get; } } struct SomeStruct : ISomeInterface { int someValue; public int SomeProperty { get { return someValue; } } public SomeStruct(int value) { someValue = value; } } and then I do this somewhere: ISomeInterface someVariable = ne...

Coldfusion 8: Array of structs to struct of structs

I've got an array items[] Each item in items[] is a struct. item has keys id, date, value (i.e., item.id, item.date, item.value) I want to use StructSort to sort the item collection by a date Is this the best way to do it in ColdFusion 8: <cfset allStructs = StructNew()> <cfloop array = #items# index = "item"> <cfset allStructs[it...

What is the logic behind defining macros inside a struct?

As apparent in the title, I'm questioning the reason behind defining the macros inside a struct. I frequently see this approach in network programming for instance following snippet: struct sniff_tcp { u_short th_sport; /* source port */ u_short th_dport; /* destination port */ tcp_seq th_seq; ...

Extension method for Int32 in C#

I envisage the ability to write fluent code that adds meaning to numbers within codebases. Say you wanted a number to represent a distance in miles. You'd have something like: Usage: var result = myMethod(100.Miles()); I think this would be much more readable than simply passing in the int, plus you could presumably apply bounds chec...

How do I fit a variable sized char array in a struct?

I don't understand how the reallocation of memory for a struct allows me to insert a larger char array into my struct. Struct definition: typedef struct props { char northTexture[1]; char southTexture[1]; char eastTexture[1]; char westTexture[1]; char floorTexture[1]; char ceilingTexture[1]; } PROPDATA; exampl...

Memory allocation of identical structs.

So I was teaching my friend about pointers. While doing so, I noticed that the address of two identical structs are exactly back-to-back. struct Foo { int a; }; struct Bar { int b; }; Which allowed me to do this: Foo foo; foo.a = 100; Bar bar; bar.b = 100; Foo *pFoo = &foo; Bar *pBar = &bar; (pFoo+1)->a = 200; This overr...

Pointers in structs passed to CUDA

Hi folks, I've been messing around with this for a while now, but can't seem to get it right. I'm trying to copy objects that contain arrays into CUDA device memory (and back again, but I'll cross that bridge when I come to it): struct MyData { float *data; int dataLen; } void copyToGPU() { // Create dummy objects to copy int ...

General Socket Question - Transferring C++ Structs from Java to C++

Hi, friends. I have a general socket programming question for you. I have a C struct called Data: struct data { double speed; double length; char carName[32]; struct Attribs; } struct Attribs { int color; } I would like to be able to create a similar structure in Java, create a socket, create the data...

Why does C++ support memberwise assignment of arrays within structs, but not generally?

I understand that memberwise assignment of arrays is not supported, such that the following will not work: int num1[3] = {1,2,3}; int num2[3]; num2 = num1; // "error: invalid array assignment" I just accepted this as fact, figuring that the aim of the language is to provide an open-ended framework, and let the user decide how to imple...

Properly copy C# structs with (byte) arrays in them?

From what I understand, when assigning a struct variable to another one, the first one is usually copied instead of creating a reference: public struct MYSTRUCT1 { public byte val1; } // (...) public DoSomething() { MYSTRUCT1 test1; test1.val1 = 1; MYSTRUCT1 test2 = test1; test2.val1 = 2; Console.WriteLine(test1...

Problem with struct and property in c#

in a file I defined a public struct public struct mystruct { public Double struct1; public Decimal struct2; } In another I tried to do this: class Test { mystruct my_va; public mystruct my_va { get { return my_va; } set { my_va = value; } } public Test() { my_va.struct1 = 10; ...

C Programming - Malloc Structs and undefined arrays

I am writing a program in C and I am trying to create these structs. I have three of them: the first consisting of 2 ints and 2 chars, the second consisting of an int and an undefined array of pointers to the first one, and a third which contains 4 longs and 2 ints along with an undefined array of pointers to the second. I am having ...

C Programming weird struct setup

I am trying to build this project and for some reason the program hangs when I run it. It works fine if i comment out the data cache lines. but it cannot make a call to makeCache for two different caches i dont know why any C experts know. Im new to c. /* * main.c * * Created on: Sep 16, 2010 * Author: TJ */ #include <std...

c# Convert struct to another struct

Hi, Is there any way, how to convert this: namespace Library { public struct Content { int a; int b; } } I have struct in Library2.Content that has data defined same way ({ int a; int b; }), but different methods. Is there a way to convert a struct instance from Library.Content to Library2.Content? Somet...

C: linked lists confusion

error: dereferencing pointer to incomplete type The problem line is "gl->point[0] = (struct list *)" I read somewhere that I could be storing a declaration. If that is the case I need that explained to me. struct ref { char **name; struct list **point; }; int main ( ) { typedef struct { char **name; s...

Byte swapping a struct

Okay I hate to ask this question ... but here goes. I am writing some code in C on an x86 machine. I want to send a struct over the network and and I want to convert the struct to Network Byte Order ... I understand all the drama about packing and the the gcc packing pragmas ... what I want to know is HOW do I convert a struct (or an arr...

Expected identifier or '(' before '.' token

I'm new to Objective-C so I'm using a book to get to grips with it. I'm at a bit where it's explaining structs and I can't for the life of me get them to work. I have the following code: int main (int argc, char *argv[]) { struct node { int nodeID; int x; int y; BOOL isActive; }; typede...