struct

Struct data type in Mathematica?

After playing with Mathematica's symbolic and numerical capabilities, I find it to be a decent programming language, too. However, something making it less appealing as a general-purpose language is the lack of C-like struct data type (or the record type as known in Pascal). How can I get around this problem? ...

Passing char array to struct member

I have the following structure: struct hashItem { char userid[8]; char name[30]; struct hashItem *next; }; In the function below I take a char pointer (char array) argument that I wish to assign to the struct. void insertItem(struct hashItem *htable[], char *userid, char *name) { int hcode = hashCode(userid); stru...

C Programming. How to deep copy a struct?

I have the following two structs where "child struct" has a "rusage struct" as an element. Then I create two structs of type "child" let's call them childA and childB How do I copy just the rusage struct from childA to childB? typedef struct{ int numb; char *name; pid_t pid; long userT; ...

Returning pointer to a local structure

Is it safe to return the pointer to a local struct in C? I mean is doing this struct myStruct* GetStruct() { struct myStruct *str = (struct myStruct*)malloc(sizeof(struct myStruct)); //initialize struct members here return str; } safe? Thanks. ...

Using structs in C# for simple domain values

I am writing a financial application where the concept of 'Price' is used a lot. It's currently represented by the C# decimal type. I would like to make it more explicit and be able to change it to maybe double in the future, so I was thinking of creating a 'Price' struct that would basically act exactly the same as the decimal type (may...

Structs in C++ can be modified? or there is a restriction?

I have this class which has a double list template of a struct of two chars and another struct typedef struct KeyC{ char K[5]; char C[9]; } TKeyC; typedef struct Bin{ char Car; char Cad[9]; TKeyC *KC; } TBin; class Bo { private: TDoubleList<TBin> *Ent; public: ... } I have a method ...

C#: What needs to be overriden in a struct to ensure equality operates properly?

As the title says: do i need to override the == operator? how about the .Equals() method? Anything i'm missing? ...

C: copying struct/array elements

Hello everyone, I have a file in a known format and I want to convert it to a new format, eg.: struct foo { char bar[256]; }; struct old_format { char name[128]; struct foo data[16]; }; struct new_format { int nr; char name[128]; struct foo data[16]; }; s...

Is it possible to force a string to be a specific size when defining a struct?

I am marshalling data between a C# and C++ application. In the C# application, I force the size of a string to be some size (say, 256 bytes). I would like to read in that exact same amount in C++ (I will be recreating the structs with reinterpret_cast) so that the data will remain formatted as it was in the C# application. Unfortunate...

Casting a 'BigStruct' to a 'SmallStruct' in C (similar structs with static arrays of different sizes)

Supposed that for some reason you are only allowed to use static memory in a C program. I have a basic structure that I am using in several places defined as below: #define SMALL_STUFF_MAX_SIZE 64 typedef struct { /* Various fields would go here */ ... double data[SMALL_STUFF_MAX_SIZE]; /* array to hold some data */ } Small...

How do I convert Perl's pack 'Nc*' format to struct.pack for Python?

I'm trying to convert a Perl script to python, and it uses quite a few different packs. I've been able to figure out the lettering differences in the "templates" for each one, but I'm having an issue with understanding how to handle Perl's lack of length declaration. example: pack('Nc*',$some_integer,$long_array_of_integers); I don't...

Divide a string into smaller parts & organize a structure (C-programming)

Hi again! I am still learning C and I'm having some trouble figuring out how to handle this. Well, I have two structs: struct myStruct { ... struct myString *text[5]; ... } allStructs; struct myString { char part[100]; }; The objective is to have allStruct[n] point to 5 different parts of a text divided into lines of...

C typedef of pointer to structure

I had come across the following code: typedef struct { double x; double y; double z; } *vector Is this a valid type definition? The code compiles and runs fine. I was just curious if this is common practice. ...

How do you define an opaque struct array in C?

I have code in my header file that looks like: typedef struct _bn bnode; I can do bnode b; just fine, but b[i], where i is an int gives me the following error: invalid use of undefined type ‘struct _bn’ Any ideas? ...

Removing Bit fields in a struct

Hey Folks, I have a question. I have a legacy application which used bit fields in a structure. Something like this struct sample { BYTE one: 2; BYTE two : 1; BYTE three: 5; } sampletest; So "three" can have a value of MAX 31 only. Now I have a requirement to increase the MAX value of three. I am planning to r...

Divide large malloc-block into smaller "partitions"

Is there a way to use poiter arithmetic on a large malloc block, so you can assign multiple structs or primitive data types to that area already allocated? I'm writing something like this but it isnt working (trying to assign 200 structs to a 15000byte malloc area): char *primDataPtr = NULL; typedef struct Metadata METADATA; struct M...

Why does Visual Studio not know the correct definition of this struct?

I've got a weird issue that almost seems like a Visual Studio 2008 issue. I have a C struct definition as follows: static struct frame { short typupdt; char callarg[1+CallSiz]; char *unitarg; XTime unitage; XTime orgtime; XTime newtime; char oldstat[1+StatSiz]; char newstat[1+StatSiz]; char incdisp[1...

Portability concerns on C struct/union

Supposing I have the following type from an external library: union foreign_t { struct { enum enum_t an_enum; int an_int; } header; struct { double x, y; } point; }; is it safe to assume the following code fragment will work as expected on different platforms and with different compilers? struc...

Is this the right way for a block inside a struct to access a member variable in the same struct?

I'm experimenting with Obj-C blocks and trying to have a struct with two blocks in it where one block is to change what the other block does. this is a really roundabout way to do something simple... and there may be better ways to do it, but the point of the exercise is for me to understand blocks. here's the code , it doesn't work, s...

Structure Generics in C#

Hi Please, help me with this problem: I Try define a structure like this: unsafe struct sNodo<T> { public T info; public sNodo<T>* sIzq;} but i get this error: Cannot take the address of, get the size of, or declare a pointer to a managed type sNodo, how can I fix it? I'm trying to create a stack "generic" usi...