struct

Can the struct padding be safely used by the user code?

Assuming I have a struct like the following: struct Struct { char Char; int Int; }; and sizeof( int ) is greater than one and the compiler adds padding for the Char member variable - is the compiler-generated code allowed to change the values of the padding bytes? I mean if I use pointer arithmetic and write some data into th...

Why do pointers use -> instead of .?

Possible Duplicate: Why does C have a distinction between -> and . ? Lets say that I have this structure: struct movies { string title; int year; } my_movie, *ptrMovie; Now I access my_movie like this: my_movie.year = 1999; Now to access a pointer I must do this: ptrMovie->year = 1999; Why do pointers use the -> oper...

Setting a value through reflection is not working.

I am trying to set a value through reflection. I created this little test program struct headerIndexes { public int AccountNum{ get; set; } public int other { get; set; } public int items { get; set; } } static void Main(string[] args) { headerIndexes headers = new headerIndexes(); ...

C: Passing Struct to a Function doesn't result in a call by value operation

Hello! I have the following problem with a program which I wrote in Visual C++ and I hope that anyone can help me please: typedef struct spielfeld { int ** Matrix; int height; int width; Walker walker; Verlauf history; } Spielfeld; void show(Spielfeld fieldToShow); //Prototype of the Function where I have this ...

Managed and unmanaged struct are not the same size

I'm working with an unmanaged library through P/Invoke and it uses three structs (although they all have the same basic layout, so I'll only post one): struct Agraph_t { int tag:4; int kind:4; int handle:24; char **attr; char *didset; char *name; Agdata_t *univ; Dict_t *nodes, *inedges, *outedges; Agr...

how to get struct's start address from its member's address

In C language, how to get struct's start address from its member's address? struct type1 { //... int member1; //... }; struct type1 obj1; And ptr1 is the address of member member1 in obj1, how to define macro #define start_add(ptr1, type1, member1) to get obj1's start address? ...

struct pointer manipulation

The Code used #include<stdio.h> struct st { char a; short c; int b; }; struct st s1; int main() { printf("%p %p \n",(&s1.b)-1, &s1); } If I print the address of &s1.b it prints 0x804a01c and &s1.b-2 prints 0x804a018 why it is printing same address 0x804a01c if i select &s1.b-1 ? ...

How can I get/set a struct member by offset

Ignoring padding/alignment issues and given the following struct, what is best way to get and set the value of member_b without using the member name. struct mystruct { int member_a; int member_b; } struct mystruct *s = malloc(sizeof(struct mystruct)); Put another way; How would you express the following in terms of pointers/o...

Volatile Struct Semantics

Is it sufficient to declare an instance of a structure-typed variable as volatile (if its fields are accessed in re-entrant code), or must one declare specific fields of the structure as volatile? Phrased differently, what are the semantic differences (if any) between: typdef struct { uint8_t bar; } foo_t; volatile foo_t foo_inst; ...

Extract the fields of a C struct

I often have to write code in other languages that interact with C structs. Most typically this involves writing Python code with the struct or ctypes modules. So I'll have a .h file full of struct definitions, and I have to manually read through them and duplicate those definitions in my Python code. This is time consuming and error-...

[C++] Using Structs -- Odd Issue

Been awhile since I've used structs in C++. Any idea why this isn't working? My compiler is complaining about DataStruct not being a recognized type but Intellisense in VC++ is still able to see the data members inside the struct so the syntax is ok... Frustating. xD struct DataStruct { int first; }; int main(int argc, char **...

dynamic array IN struct, C

I have looked around but have been unable to find a solution to what must be a well asked question. Here is the code I have: #include <stdlib.h> struct my_struct { int n; char s[] }; int main() { struct my_struct ms; ms.s = malloc(sizeof(char*)*50); } and here is the error gcc gives me: error: invalid use of flexibl...

Best Way To Marshal A Pointer of Array of Struct

I'm calling functions from C++ that returns a pointer to an array of struct and I'm having problems since I'm new to this operation/implementation. My C++ codes: // My C++ Structs typedef struct _MainData { double dCount; DataS1 *DS1; int iCount1; DataS2 *DS2; int iCount2; }MainData; typedef struct _DataS1 { ...

Ways To Marshal A Pointer of Array of Struct

I'm calling functions from C++ that returns a pointer to an array of struct and I'm having problems since I'm new to this operation/implementation. My C++ codes: // My C++ Structs typedef struct _MainData { double dCount; DataS1 *DS1; int iCount1; DataS2 *DS2; int iCount2; }MainData...

How to find all the structs that could be made smaller by changing the order of their members.

Background: The compiler may insert padding into a struct to make it's members align better. This will result in the sizeof the struct being larger than the sum of the sizes of it's members. Reordering the members of the structure so they pack better can remove the need for the compiler to pad in this manner and make the struct smaller s...

C# Value Type Class Template

I'm writing/written a value type struct and was wondering if there was a guide that contains a standard template for method signatures and interface implementation. I thought I'd start by looking at the System.Double documentation: struct def public struct Double : IComparable, IFormattable, IConvertible, IComparable<double>, IEquata...

Passing arrays vs structures to functions

In C, arrays are passed to functions as pointers. Structures can be passed to functions either by value or by address (pointer). Is there any specific reason why we can not pass array by value but we can pass structre by value ? ...

Program stops without error on struct member assignment

I have a function which accepts a pointer to a struct and sets a member of that struct to a specific value. However, after that assignment code is executed, and my program exits without showing any errors. void swn_addClassToInstance(struct instanceR *instance) { instance->classCount = 0; //nothing below here will run } I'm new to C...

Initializing static struct tm in a class

Hi all, I would like to use the tm struct as a static variable in a class. Spent a whole day reading and trying but it still can't work :( Would appreciate if someone could point out what I was doing wrong In my class, under Public, i have declared it as: static struct tm *dataTime; In the main.cpp, I have tried to define and initia...

How can I work with a struct returned from a cfc in jquery

I have a cfc <cffunction name="addEditPerson" access="remote" returntype="struct"> a bunch of cfarguments <cfscript> var returnThis = structNew(); var error = ''; structInsert(returnThis,'success',0,true); structInsert(returnThis,'error','',true); structInsert(returnThis,'pers...