struct

Can't add value to List in C#

I'd like to add a value to a struct if (!existISDNteilnehmer(split)) { isdnObjs.Add(new ISDN() { name = split, number = "", channels = new List<string>()}); } ISDN? actualISDN = getISDN(split); if (index < ISDN_teilnehmer.Count()) { var numbers = from num in xISDN.XPathSelect...

Handle empty structs in Objective-C (Coordinate in custom class)

I have a custom class that has as an instance variable of a coordinate: CLLocationCoordinate2D eventLocation; @property(nonatomic) CLLocationCoordinate2D eventLocation; I'm parsing an xml file that has an optional field that may or may not be there. If it is i set it like so: CLLocationCoordinate2D location; NSArray *coordinateArray ...

What does the : do in a struct declaration after a member

In: struct foo { unsigned bar : 2; }; What does the ': 2' do? ...

typedef struct vs struct definitions

I'm a beginner with C programming, but I was wondering what the difference was between the using typedef when defining a structure versus not using typedef. It seems to my like there's really no difference, they accomplish the same. struct myStruct{ int one; int two; }; vs. typedef struct{ int one; int two; }myStruct;...

Marshalling struct with embedded pointer from C# to unmanaged driver

Hi, I'm trying to interface C# (.NET Compact Framework 3.5) with a Windows CE 6 R2 stream driver using P/Invoked DeviceIoControl() calls . For one of the IOCTL codes, the driver requires a DeviceIoControl input buffer that is the following unmanaged struct that contains an embedded pointer: typedef struct { DWORD address; cons...

Changing a stuct inside another struct in a foreach loop

The following code prints (when invoking MyMethod): 0 0 0 1 I would expect it to print: 0 0 1 1 Why is this? Code: private struct MyStruct { public MyInnerStruct innerStruct; } private struct MyInnerStruct { public int counter; public void AddOne() { ++counter; } } public static void MyMethod() ...

MSVC: what compiler switches affect the size of structs?

I have two DLLs compiled separately, one is compiled from Visual Studio 2008 and one is a mex file compiled from matlab. Both DLLs have a header file which they include. when I take the sizeof() the struct in one DLL it returns 48, and in the other it returns 64. I've checked the /Zp switch and in both compilations it is set to /Zp8. Wha...

Initialization of reference member requires a temporary variable C++

struct Div { int i; int j; }; class A { public: A(); Div& divs; }; In my constructor definition, I have the following A::A() : divs(NULL) {} I get the following error: Error72 error C2354: 'A::divs' : initialization of reference member requires a temporary variable ...

Constant Pointer / structs

In my programming class, we have struct Time { int hours, min, sec; } We are to create a method to compute the difference between two times: Time *timeDiff(const Time *t1, const Time *t2) I thought I could create the time difference by getting everything in seconds, and then subtracting the two values, but it seems like extra wo...

Struct initialization of the C/C++ programming language?

I could do struct initialization with code: struct struct_type_id struct_name_id = { value1, value2, value3 }; but could not with: struct struct_type_id struct_name_id; struct_name_id = { value1, value2, value3 }; why I could do it with the former,but could not with the latter with gcc,g++,vc2008,vc6?In other words,why the c/c++ pr...

Inserting leading zeros into an integer

I have a function in C which generates a number of hours from a rtc peripheral, which I then want to fill an array within a struct object. The array is set up to take 5 digits, but I need to prepend leading zeros to the number when it is less than 5 digits. Could anyone advise on an easy way of achieving this? ...

Returning a C++ class to Java via JNI

Hello, I'm currently using both C++ and Java in a project and I'd like to be able to send an object which is contained in C++ to my Java interface in order to modify it via a GUI and then send the modification back in C++. So far I've been returning either nothing, an int or a boolean to Java via the JNI interface. This time I have to ...

Is there an existing Python class that can hold any user attributes?

I can use this when I need multiple objects with different attributes: class struct(object): def __init__(self,*args,**kwargs): for key,val in kwargs.items(): setattr(self,key,val) But I'm wondering if there isn't a built-in already? ...

Scheme, getting the pointer from pointed struct

Assume I have a such struct: (define-struct node (value next)) ;and making 2 nodes, parent pointing to child as next. (define child (make-node 2 null)) (define parent (make-node 1 child)) Under PLT Scheme, while having child in my hand (and not knowing that parent is the pointer), is it possible to find the pointing node sctuct with...

Sending struct over TCP (C-programming)

Hi again! I have a client and server program where I want to send an entire struct from the client and then output the struct member "ID" on the server. I have done all the connecting etc and already managed to send a string through: send(socket, string, string_size, 0); So, is it possible to send a struct instead of a string throug...

Access variables in C structures

Dear all! I am not too familiar with C programming, and I have to do few modifications on a source code, here is the problem: I have this in a header file : typedef struct word { long wnum; float weight; } WORD; typedef struct svector { WORD *words; double norm; } SVECTOR; In my file.c , I have a function like doubl...

Why does my object take up 64 bytes and not 32?

I have a class that goes like this: class myType { union { float data[4]; other_vector4_type v } ; typedef union { float data[4]; other_vector4_type v } myType-internal_t; <various member functions, operator overloads> } Now I want to use this type in my vertex buffer, but the sizeof() isn't as expe...

Does GCC's __attribute__((__packed__))...?

Purpose I am writing a network program in C (specifically gnu89) and I would like to simplify things by reinterpreting a certain struct X as big array of bytes (a.k.a. char), sending the bytes over the network, and reinterpreting them as struct X on the other side. To this end I have decided to use gcc's __attribute__((__packed__ )). I ...

passing primitive or struct type as function argument

I'm trying to write some reasonably generic networking code. I have several kinds of packets, each represented by a different struct. The function where all my sending occurs looks like: - (void)sendUpdatePacket:(MyPacketType)packet{ for(NSNetService *service in _services) for(NSData *address in [service addresses]) ...

Nested struct variable initialization

How can I initialize this nested struct in C? typedef struct _s0 { int size; double * elems; }StructInner ; typedef struct _s1 { StructInner a, b, c, d, e; long f; char[16] s; }StructOuter; StructOuter myvar = {/* what ? */ }; ...