struct

Coding : Using Struct as a DataUtility/Library for Harcode values (Constants)

Is it OK to use Structs as Data library for harcoded values? Sometimes we can't avoid harcoding somethin althought its better to put it on something like xml file or a database table, but sometimes it's not possible for some reasons.. public struct BatchStatus { public const string Submitted = "0901XX"; public const string Act...

problem with variable assignment to arrays using structs in c

So I'm trying to multiply matrices in c. However when I try to multiply the numbers in the two arrays, and put them in an answer array its always zero. heres the code for the method, thanks. My matrix struct: typedef struct matrix { int r; int c; double **mat; } *matrix_t; My matrix multiplying method: matrix_t mat_mult(matrix_t...

Having trouble accessing struct elements returned by a function - dereferencing pointer to incomplete type

I am new to C.This are the files and codes that I am working on. I am trying to call a function (refineMatch) implemented in a separate file from the main function. function refineMatch returns a struct. I am having problems in compiling the code which is related to accessing elements in the returned struct. The compile error occurs in m...

Reading and writing C struct from embedded lua

I'd like to embed lua to allow scripting in my C++ application. In particular, I have two structs which I'd like to pass as arguments to a given lua function. One will be read-only, the other will be read/write. Highly simplified examples of these structs follow: struct inData { int x; int y; //many other fields follow }; s...

Struct with array member in C

Recently I reviewed some C code and found something equivalent to the following: struct foo { int some_innocent_variables; double some_big_array[VERY_LARGE_NUMBER]; } Being almost, but not quite, almost entirely a newbie in C, am I right in thinking that this struct is awfully inefficient in its use of space because of the arr...

C++ structs Interdependency

Hello i have structures declared in the same Header file that need eachother. struct A; // ignored by the compiler struct B{ A _iNeedA; //Compiler error Here }; struct A { B _iNeedB; }; this work normally class A; class B{ A _iNeedA; }; class A { B _iNeedB; }; // everything is good Thank you very much! ...

Forward declarations for variables?

I have some C code that I have to port to C++. The code has a structure struct A { ... struct A * myPtr; } And now two global arrays are declared and initialized like this: //Forward declaration of Unit struct A Unit[10]; struct A* ptrUnit[2] = { Unit, Unit+7 }; struct A Unit[10] = { { .., &ptrUnit[0] }, ...

Flexible array of pointers to char in a struct - Please help!!!

Hi all, I'm trying to implement a ring buffer with the following struct /*head, tail are indexes of the head and tail of ring buffer *count is the number of elements; size is the max size of buffer *rbArray is an array to pointer of char used to store strings */ struct rb{ int head; int tail; int count; int size; char...

Re-interpreting a byte array as an array of structs

I've got a byte array that I want to re-interpret as an array of blittable structs, ideally without copying. Using unsafe code is fine. I know the number of bytes, and the number of structs that I want to get out at the end. public struct MyStruct { public uint val1; public uint val2; // yadda yadda yadda.... } byte[] stru...

Windbg with SOS, How to dump a c# struct

How do I dump a struct using windbg, is there a dumpstruct command similar to dumpobject? Or can dumpobject dump structs aswell? ...

C - accessing a struct from dynamic memory

I'm writing a program with struct Record. As I read in records from text in a loop, I assign them to buffer before saving buffer into the array. nRange is just the total number of records being read. Record *storage; storage = (Record*)malloc(nRange*sizeof(Record)); Record buffer; storage[i] = buffer; I want to access storage[i] in...

Size of a struct with two void pointers is 4?

I don't understand why struct e{ void * a; void * b[]; } has sizeof(e) == 4 while struct f{ void * a; void * b; } has sizeof(f) == 8. ...

How to compare two struct lists?

I have a small struct and I have to compare the values to find which ones have the same FreeFlow text, and then grab that struct ENumber. public struct Holder { public string FreeFlow; public int ENumber; } and here is how I add them foreach(Class1.TextElement re in Class1._TextElements) { ...

On what platforms will this crash, and how can I improve it?

I've written the rudiments of a class for creating dynamic structures in C++. Dynamic structure members are stored contiguously with (as far as my tests indicate) the same padding that the compiler would insert in the equivalent static structure. Dynamic structures can thus be implicitly converted to static structures for interoperabilit...

Is a C# struct ever boxed when used as the return value of a function?

A simple question, but I haven't found a definitive answer on Stack Overflow. struct foo { int x; int y; int z; } foo Func() { return new foo(); } void Func2() { foo f = Func(); // did boxing and unboxing occur? } Is a C# struct (value type) always copied to the stack when returned fro...

C# struct instantiation at runtime.

Could anyone provide an example how to create a structure instance at runtime? The structure I'm using doesn't define any constructors, just fields. The GetConstructor() method returns null, and so far I was unable to find a way to achieve this. ...

packing and unpacking variable length array/string using the struct module in python

Hi, I am trying to get a grip around the packing and unpacking of binary data in Python 3. Its actually not that hard to understand, except one problem: what if I have a variable length textstring and want to pack and unpack this in the most elegant manner? As far as I can tell from the manual I can only unpack fixed size strings dire...

C Struct pointer as Parameter

I'm trying to pass a pointer to a struct in C but i cannot: float calcular_media(struct aluno *aluno) { Output warning: C:\WINDOWS\system32\cmd.exe /c gcc main.c aluno.c aluno.c:7:29: warning: 'struct aluno' declared inside parameter list What am I doing wrong? Thank you. ...

malloc fails catastrophically

I am trying to implement a Queue in C. Coming from Java and other managed languages, I am really struggling with memory management. Here is the enqueue() function: int enqueue(Queue q, int value) { Node newNode = malloc(sizeof(Node)); /*newNode->value = value; if (q->size == 0) q->head = newNode; else q...

Casting one struct pointer to other - C

Please consider the following code. enum type {CONS, ATOM, FUNC, LAMBDA}; typedef struct{ enum type type; } object; typedef struct { enum type type; object *car; object *cdr; } cons_object; object *cons (object *first, object *second) { cons_object *ptr = (cons_object *) malloc (sizeof (cons_object)); ptr->type = CONS; ...