struct

When is it worth using a pointer to struct in a struct definition?

Sorry if the question isn't clear; I found it pretty hard to explain in one sentence. Say I have a struct with a member which is a struct, e.g. the following: struct A { struct B b; }; Lets say I intend instances of this structure to be heap-allocated always. Is there anything to be gained by changing it to this? (i.e. keeping a ...

C Malloc to a Pointer Through Function Call Causes Bus Error

Due to my feeble understanding of allocating type memory to pointers, the following causes a bus error on the call to barrier_create ("hi" is never printed). typedef struct barrier barrier_t; typedef struct barrier *barrier_p; barrier_p test_barrier_p; int main(int argc, char *argv[]) { barrier_create(*test_barrier_p); } int barr...

Empty structure in C

I have a structure with no member (for the moment) and I would like to know if it is possible to suppress the warning I get: warning: struct has no members Is it possible to add a member and keep the sizeof the struct zero? Any other solution? ...

Bind multiple TextBoxes to one struct in WPF

How do i bind two TextBox objects to a System.Windows.Size struct? The binding only has to work in this direction: (textBox1.Text + textBox2.Text) => (Size) After a user inserts the width and height in the TextBoxes on the UI the Size object should be created. XAML: <TextBox Name="textBox_Width" Text="{Binding ???}" /> <TextBox Name=...

How to properly use structs inside a class?

Using: VS2008, Win32, C/C++ I'm trying to encapsulate my entire dialog window into a class for reusability. Sort of like a custom control. In doing this, I am moving my seperate functions into a class. The following struct design though is giving me problems, with Visual Studio outputting: error C2334 '{'. It's a simple message map ...

C hard coding an array of typedef struct

This is such a dumb question it's frustrating even asking it. Please, bear with me, I'm feeling particularly dumb over this one today.... I've got a library with a certain typedef struct. basically: typedef struct {int x; int y;} coords; What I really wanted to do was declare in my header a variable array of this: coords MyCoord...

Will this be out of scope and not function properly?

I'm declaring a struct inside my code and then trying to insert it into a data structure that I have written. However, I'm concerned that since I declare the struct inside the function, once the function ends, the data structure will be pointing to garbage. Can anyone help with this? Here's the code: void Class::function() { // do ...

How to dynamically create and read structs in C?

Hello! How can I do something like that (just an example): any_struct *my_struct = create_struct(); add_struct_member(my_struct, "a", int_member); add_struct_member(my_struct, "b", float_member); So that I could load and use a struct instance "from the outside" (at the address addressOfMyStruct) with the given structure here? any_st...

c, problems with using struct

Hi all, I'm trying to write a program that reads text from external file (string string int, per line). Struct is defined outside of main function: typedef struct Person { char fname[15]; char lname[20]; unsigned long int birth; } clovek; I don't need "clovek" to be an array as with every line data can be overwritten. Line is re...

What does the following C++ struct syntax mean..

If I have a C++ struct, defining a 64bit data word such as.. struct SMyDataWord { int Name : 40; int Colour : 24; }; What does the : 40 syntax mean... does it mean that the first 40 bits are reserved for the Name and the remaining 24 bits for the Colour? This is how it appears to be being used, but I've not come across it be...

Why short is stored as 4 bytes in a struct in C?

I have the following two structs: The problem is the sizeof(Content) returns 160. The struct consists of 11 shorts, 6 ints, 76 chars, 7 floats, 1 double, totally adding to 158 bytes. I have counted three times and there is still a 2 byte difference. typedef struct TIME_T { short year,mon,day; short hour,min,sec; } TIME; typ...

What types to use for boxing in generics

I've written a simple abstract generic class in C# (.NET 2.0) and I preferably want to limit it to only reference types, so I can indicate no value by a null. However, I also want to use types such as long and decimal, why don't allow null (being structs after all). I considered making the class public abstract Field<Nullable<T>> { ...

How do I access internal members of a union?

I have a union that is defined like this: typedef union { enum { REVISION = 0, CURRENT_VERSION = REVISION }; enum FLAGS{ FLAG_DEFAULT = 0x00000000, FLAG_EOD = 0x00000001, FLAG_OUTOFORDER = 0x00000002 }; CHAR _filler[32]; struct INTERNAL_STRUCTURE { UINT16 ...

How large structs can be passed by value efficiently?

The rule of thumb is that it is okay to pass small structs by value and larger ones should be done pointers. My question is where exactly is this cutoff point? How large can the structures be before you are better off passing them by pointer. I know this will vary between platforms, but I assume some rough estimates could be given. A ...

How do I convert a big-endian struct to a little endian-struct?

I have a binary file that was created on a unix machine. It's just a bunch of records written one after another. The record is defined something like this: struct RECORD { UINT32 foo; UINT32 bar; CHAR fooword[11]; CHAR barword[11]; UNIT16 baz; } I am trying to figure out how I would read and interpret this data on a Windows...

Passing structures as arguments while using pthread_create()

I tried passing a structure as the 4th argument while using pthread_create() with something like this: pthread_create(&tid1, NULL, calca, &t); //t is the struct Now whenever I try to access variables in the structure - t.a, t.b or t.c, I keep getting an error - request for member in something not a structure or union. What alternate ...

c++ sort with structs

Hi, I am having a hard time with this problem which requires a sort of customer names, customer ids, and finally amount due. I have the whole program figured, but cannot figure out the last prototype needed to do the sorting. i have a struct called Customers, and i will provide the int main() part also. I just need any help to gt started...

Struct members alignment in Visual C++ 2008

Visual C++ let's you select the struct members alignemnt in the project's properties page. Problem is, this configuration is being used for all srtructs in the project. Is there any way (VC++ specific, I'd guess) to set a certain struct's member alignment individually? ...

getting a substruct out of a big struct in C

I'm having a very big struct in an existing program. This struct includes a great number of bitfields. I wish to save a part of it (say, 10 fields out of 150). An example code I would use to save the subclass is: typedef struct {int a;int b;char c} bigstruct; typedef struct {int a;char c;} smallstruct; void substruct(smallstruct *s,bi...

Interop between C++ and C#

I have this struct in C++: struct TEXTMSGSTR { HWND Sender; wchar_t Text[255]; //wchar_t *Text; }; and in C#: public struct TEXTMSGSTR { public IntPtr Sender; public ? Text; } which I am sending as part of a COPYDATASTRUCT message from unmanaged to managed code. What would be the correct construction of the stru...