struct

Figure out function argument from custom struct?

I have a function which takes a custom struct as the argument. how can I figure out what the argument should be? I know it is a date format of sorts... (C library imported to Objective-C...) Struct: typedef struct { /** The number of day in the hebrew month (1..31). */ int hd_day; /** The number of the hebrew month 1..14 (...

How to move a struct into a class?

I've got something like: typedef struct Data_s { int field1; int field2; } Data; class Foo { void getData(Data& data); void useData(Data& data); } In another class's function, I might do: class Bar { Data data_; void Bar::taskA() { Foo.getData(data_); Foo.useData(data_); } } Is there a way to move the Data ou...

C#: Struct Constructor: "fields must be fully assigned before control is returned to the caller."

Here is a struct I am trying to write: public struct AttackTraits { public AttackTraits(double probability, int damage, float distance) { Probability = probability; Distance = distance; Damage = damage; } private double probability...

Working with fields which can mutate or be new instances altogether

Structs are usually used for immutable data, eg a phone number, which does not mutate, but instead you get a new one (eg the number 000 becoming 0001 would mean two seperate numbers). However, pieces of information like Name, a string, can either mutate (company abc changing its name to abcdef, or being given a new name like def). For f...

Overriding Equals method in Structs

I've looked for overriding guidelines for structs, but all I can find is for classes. At first I thought I wouldn't have to check to see if the passed object was null, as structs are value types and can't be null. But now that I come to think of it, as equals signature is public bool Equals(object obj) it seems there is nothing preve...

"Parse error" in struct declaration

I want to use some basic struct in C like the following: struct p { int a; int b; p * next; } However, it fails to compile with an error: parse error before "p" on the line with p * next;. Do you have any idea what the reason could be for this problem? ...

C++ DLL Injection get Struct values

I am trying inject into a dll that sends a void ** for one of the parameters. The void ** can contain structs that are created in the application. Is there any way of getting data out of the structs. ...

How to have struct members accessible in different ways

I want to have a structure token that has start/end pairs for position, sentence, and paragraph information. I also want the members to be accessible in two different ways: as a start/end pair and individually. Given: struct token { struct start_end { int start; int end; }; start_end pos; start_end sent; start_end p...

Why might stable_sort be affecting my hashtable values?

I have defined a struct ABC to contain an int ID, string NAME, string LAST_NAME; My procedure is this: Read in a line from an input file. Parse each line into first name and last name and insert into the ABC struct. Also, the struct's ID is given by the number of the input line. Then, push_back the struct into a vector masterlist. I a...

Objective C Class or struct?

I have a class Song with properties Title, Key, Artist, etc. There are no methods. I loop through a database of song information and create a Song object for each, populating the properties, and then store the Song objects in an NSArray. Then I thought, why not just have a struct Song with all those same properties instead of a class So...

look up constants based on value.

I have a 3rd party struct that is comprised of the following: [StructLayout(LayoutKind.Sequential, Size=1)] public struct BigBlueReasonCodes { public const int ABC_REASONCODE_DESCRIPTION001 = 1000; public const int ABC_REASONCODE_DESCRIPTION002 = 1005; public const int ABC_REASONCODE_DESCRIPTION003 = 1010; public const i...

C Structure Pointer Problem

I have this struct; #define BUFSIZE 10 struct shared_data { pthread_mutex_t th_mutex_queue; int count; int data_buffer_allocation[BUFSIZE]; int data_buffers[BUFSIZE][100]; }; and I want to allocate one of the data_buffers for a process, for that purpose I execute the following function; int allocate_data_buffer(int p...

C++ min heap with user-defined type.

Hi, I am trying to implement a min heap in c++ for a struct type that I created. I created a vector of the type, but it crashed when I used make_heap on it, which is understandable because it doesn't know how to compare the items in the heap. How do I create a min-heap (that is, the top element is always the smallest one in the heap) fo...

getnameinfo prototype asks for sockaddr not sockaddr_in ?

The getnameinfo prototype asks for sockaddr but I have only seen examples using sockaddr_in. Can this example be re-written for sockaddr ? sin_family becomes sa_family but what about sin_port and sin_addr ? How are they included in sa_data ? struct sockaddr{ unsigned short sa_family; char sa_data[14]; }; struct soc...

C programming: Dereferencing pointer to incomplete type error

Hi, I am pretty rusty at C, and I'm getting a dereferencing error. Hopefully someone can help me with this? ^_^ I have a struct defined as: struct { char name[32]; int size; int start; int popularity; } stasher_file; and an array of pointers to those structs: struct stasher_file *files[TOTAL_STORAGE_SIZE]; In my code, I'm ...

pthread with unique struct as parameter C

I have this piece of code that is giving me trouble. I know all the threads are reading the same struct. But I have no idea how to fix this. #include <pthread.h> #include <stdio.h> #include <stdlib.h> typedef struct { int a,b; } s_param; void * threadfunc(void *parm) { s_param *param2 = parm; printf("ID:%d and v:%d\n",param2->a...

c incompatible types in assignment, problem with pointers?

Hi I'm working with C and I have a question about assigning pointers. struct foo { int _bar; char * _car[SOME_NUMBER]; // this is meant to be an array of char * so that it can hold pointers to names of cars } int foofunc (void * arg) { int bar; char * car[SOME_NUMBER]; struct foo * thing = (struct foo *) arg; bar =...

C: External const ints in a array of const struct

I am getting an error message "expression must have constant value" when initializing an array of structures with an external constant integer. File1.c: const unsigned char data1[] = { 0x65, 0xF0, 0xA8, 0x5F, 0x5F, 0x5F, 0x5F, 0x31, 0x32, 0x2E, 0x31, 0xF1, 0x63, 0x4D, 0x43, 0x52, 0x45, 0x41, 0x54, 0x45, 0x44, 0x20,...

Dereference a pointer inside a structure pointer

I have a structure: struct mystruct { int* pointer; }; structure mystruct* struct_inst; Now I want to change the value pointed to by struct_inst->pointer. How can I do that? EDIT I didn't write it, but pointer already points to an area of memory allocated with malloc. ...

Array of structures CLI

public value struct ListOfWindows { HWND hWindow; int winID; String^ capName; }; thats my structure now i have created an array of them: array<ListOfWindows ^> ^ MyArray = gcnew array<ListOfWindows ^>(5); now to test if that works i made a simple function: void AddStruct( ) { HWND temp = ::FindWindow( NULL, "Test" ); if( te...