struct

Struct's contribution to type size

I am wondering why the following two types struct { double re[2]; }; and double re[2]; have the same size in C? Doesn't struct add a bit of size overhead? Thank you in advance. ...

doubts in double pointer in C

the follwing code is run successfully ... typedef struct _s { int *r; }s; void main() { s *u; int y=1000; u=malloc(sizeof(s)*8); u->r=malloc(sizeof(int)*8); u->r[5]=y; printf("%d\n",u->r[5]); getch(); } but i write the follwing code as above but gives error ....i use structure.....may why i know the reaso...

Is a struct of pointers guaranteed to be represented without padding bits?

I have a linked list, which stores groups of settings for my application: typedef struct settings { struct settings* next; char* name; char* title; char* desc; char* bkfolder; char* srclist; char* arcall; char* incfold; } settings_row; settings_row* first_profile = { 0 }; #define SETTINGS_PER_ROW 7 When I load values ...

Pass and access structures using objective-c

I want to know how to pass structures to another function and subsequently access that structure in the called function. I'm developing for the iPhone and the reason I'm using structs is so that I can eventually pass data as structs to a server being built in C. Here's the structure: struct userInfo{ NSString *firstName; NSStri...

How to track down cause of missing struct from include files in C?

Hey, I have a rather large project I'm porting, and in one of the MANY headers I've included a file that contains a struct definition for pmc_mdep. (prior in the file its just declared, but later its actually defined). Trying to compile it gives me errors about that struct being an incomplete type (which I believe means that it's lack...

Calling a Delphi DLL from C# containing Pointer in struct not working

I have a delphi dll that is defined like this type tSSL_connect = packed record pssl : Pointer; pctx : Pointer; sock : Integer; end; function SSLCLT_Connect(pIPAddr: PChar; iPort: Integer; var pConn: tSSL_connect; iTimeout: Integer; bEnableNonBlockingMod...

Purpose of struct, typedef struct, in C++

In C++ it is possible to create a struct: struct MyStruct { ... } And also possible to do the following: typedef struct { ... } MyStruct; And yet as far as I can tell, no discernable difference between the two. Which is preferable? Why do both ways exist if there is no difference? Is one better than the other in style or re...

Getting all variables inside a struct of unknown size (C#)

I have a project in which I have to get all the variables from a struct in a different class and add all their names to a combo box in a form. My primary issue at the moment is iterating through the struct in a way that I can add each variable individually to the combo box. I tried doing this: msgVars vars = new msgVars(); ...

C Typedef and Struct Question

What's the difference between these two declarations, and is one preferred over the other? typedef struct IOPORT { GPIO_TypeDef* port; u16 pin; } IOPORT; typedef struct { GPIO_TypeDef* port; u16 pin; } IOPORT; ...

MSVC: union vs. class/struct with inline friend operators

This piece of code compiles and runs as expected on GCC 3.x and 4.x: #include <stdio.h> typedef union buggedUnion { public: // 4 var init constructor inline buggedUnion(int _i) { i = _i; } friend inline const buggedUnion operator - (int A, const buggedUnion &B) { return buggedUnion(A - B.i); } ...

How is a struct defined as a property?

The title may be incorrect, if so please change. I'm not sure how to ask my question so just look at the code as it should be obvious. Using the commented code will work but I want to know why the actual code does not work. I'm sure it's wrong but how can it be fixed? Or is this not how its done? using System; namespace SomethingAwful...

MATLAB: collect from array of structs

The output of eg >>w = whos; returns an array of structs. I would like to construct an array whose elements are the scalars from a particular field name in each struct. The most obvious way of doing this doesn't return an array as I want, but each answer separately. >> w(1:2).bytes ans = 64 ans = 128 I could do it with a loop...

How to store a value of NSString as char array within a structure in Objective-C?

I am having trouble assigning the value of an NSString to a char * within a structure of a singleton class. The following is a simplification of my problem. My code utilizes more fields in the structure and passes more NSStrings. Say I have a singleton class "SingletonClass" with a structure (I've done my homework with the Apple Documen...

Is there an alternative for StructLayout "Pack" attribute in Compact Framework?

I would like to do the following: [StructLayout(LayoutKind.Sequential, Pack = 1)] public struct SomeStruct { public byte SomeByte; public int SomeInt; public short SomeShort; public byte SomeByte2; } Is there an alternative since Pack is not supported in the compact framework? Update: Explicitly settin...

Struct initialization problem?

Hi, I'm using a struct like this: define struct _Fragment{ int a; char *seq; }Fragment; I want to initialize the struct, and using the malloc() method return a dynamic memory like this Fragment *frag=malloc(10*sizeof(Fragment)); Then I would using the frag pointer like this: frag->seq="01001"; Then the problem occurs...

Alternatives to using pack_into() when manipulating a list of bytes?

I'm reading in a binary file into a list and parsing the binary data. I'm using unpack() to extract certain parts of the data as primitive data types, and I want to edit that data and insert it back into the original list of bytes. Using pack_into() would make it easy, except that I'm using Python 2.4, and pack_into() wasn't introduced u...

How to write a NSMutableArray of a struct type that also includes NSMutableArray inside of it?

I was wondering if there is any sample code out there for objective-C for implementing a NSMutableArray of type struct. Inside, I need there to be 2 mutable arrays (via NSMutableArray also) declared in the struct. All the code samples in my book show me how to make an array of defined size via C array syntax (with the brackets), but I do...

low level C++ style i/o in C# for reading FAT32

i am workign on reading the FAT32 entry of the harddisk and so far have been successful in reading the entries by makign use of the following APIs CreateFile, ReadFile, SetFilePointer. Here is my code in C# written so far. ---The DLL IMPORTS----- [DllImport("kernel32.dll", SetLastError = true)] static extern IntPtr CreateFile(...

Declare and initialise an array of struct/class at the same time

1. I know that it is possible to initialise an array of structures in the declaration. For example: struct BusStruct { string registration_number; string route; }; struct BusStruct BusDepot[] = { { "ED3280", "70" }, { "ED3536", "73" }, { "FP6583", "74A" }, }; If the structure is changed into a class, lik...

How do I marshal an array of bytes to a struct?

Related Question In the related question, I was trying to figure out the fastest way. The method I chose in that question has become a bottle neck for me. I am reading some binary data from a file and need to put it into a managed structure definition. No unmanaged code is involved so I'm thinking there is a better way than allocating t...