struct

Printing the address of a struct object

I have a struct like this typedef struct _somestruct { int a; int b; }SOMESTRUCT,*LPSOMESTRUCT; I am creating an object for the struct and trying to print it's address like this int main() { LPSOMESTRUCT val = (LPSOMESTRUCT)malloc(sizeof(SOMESTRUCT)); printf("0%x\n", val); return 0; } ..and I get this warning ...

C++ vector and struct problem win32

I have a structure defined in my header file: struct video { wchar_t* videoName; std::vector<wchar_t*> audio; std::vector<wchar_t*> subs; }; struct ret { std::vector<video*> videos; wchar_t* errMessage; }; struct params{ HWND form; wchar_t* cwd; wchar_t* disk; ret* returnData; }; When I try to add my video structure to a vecto...

Declaration of struct variables in other class when obtained by getters

Hi, I am using Qt 4.5 so do C++. I have a class like this class CClass1 { private: struct stModelDetails { QString name; QString code; ..... // only variables and no functions over here }; QList<st...

C# data binding to a struct - easily achievable?

Hi, I face the following problem. I want to bind a C# struct with least effort to a grid control. The grid control should show the struct members (the variable names and the value strored in the variable) i.e. let's say I have a struct like the following struct A { string name; int value; } A.name="huhu"; A.value=3; I would want t...

C++ Union, Struct, Member type

If I have a class: class Odp { int i; int b; union { long f; struct { WCHAR* pwszFoo; HRESULT hr; }; }; } Union means that, of all values listed, it can only take on one of those values at a time? How does that work in terms of accessing these varia...

C# - 2 struct questions

Hi, I know structs are value types but then I do not understand why this works: EDIT: I mean, why this.Size.Height does not work then? struct A { int height; public int Height { get { return height; } set { height = value; } } } //... class Main ...

Given a pointer to member a within a struct, write a routine that returns a pointer to the struct.

Here is an interview question that I saw on some forum. I've been trying to figure out how it works but I don't quite get it. Could somebody explain how it works? Q: Given a pointer to member a within a struct, write a routine that returns a pointer to the struct. struct s { ... int a; … }; struct s *get_s_ptr(int *a_ptr) ...

looping through properties in struct - C

Can I use a forloop to get the property names of a "struct" in C? Or would I just have make a separate list? (Just the name I am looking for) ...

Initialize and return a struct in one line in C++

Is this possible? I know that you can initialize structs using list syntax. IE struct Foo f = { a, b, c}; return f; is a possible to do this in one line as you would be with classes and constructors? Thanks ...

In C, does an array of a structure gets allocated in the stack?

I think this maybe a really dumb question, but i just want to be clarified. Thanks in advance! I'm not sure if an array of structure declared as a local variable inside a function gets allocated in the stack. Doesn't? ...

unfamiliar with struct/class declaration with template

while going through some of the mili source code I came across a struct declared like this: template <class T, class Pre, class Pos> struct PrePosCaller<T*, Pre, Pos> (from here) The part I'm unfamiliar with is <T*, Pre, Pos>. I understand what the code does and its purpose in this context but I would like to know where it is documen...

Fast vector struct that allows [i] and .xyz-operations in D?

I'd like to create a vector struct in D that works like this: vec u, v; vec w = [2,6,8]; v.x = 9; // Sets x v[1] = w.y; // Sets y u = v; // Should copy data Later I'd also like to add stuff like u = v * u etc. But the above will do for now. This is how far I've come: struct vec3f { float[3] data; alias data this; @propert...

ext3 code understanding

struct inode_operations ext3_dir_inode_operations = { .create = ext3_create, .lookup = ext3_lookup, } This struct is assign to inode structure and further to file system operation structure. My question is what is this flag .create? Do we do the assignment in the structure itself? Or is it some other ver...

member alignment in c struct-embedded union

Hi I am modifying a bit of C code, that goes roughly like this: typedef struct STRUCT_FOO { ULONG FooInfo; union { ULONG LongData; USHORT ShortData; UCHAR CharData; }; } FOO; ... FOO foo; ULONG dataLength = offsetof(FOO, CharData) + sizeof(foo.CharData); Obviously, the code tries to figure o...

C++: Construct subclass from base class instance?

I have three structs, one of which inherits from the other two: typedef struct _abc { int A; int B; int C; } ABC; typedef struct _def { int D; int E; int F; } DEF; typedef struct _abcdef : ABC, DEF { } ABCDEF; (I want the third struct to contain all the members of the first two. Is there a better way to do i...

Passing a struct with multiple entries in c++

I am trying to pass a coordinate, which is defined as struct with 2 integer parameters (the struct is called coord) the following way: UpdateB({0,0}); where the input argument is of type coord (i.e. in the above statement I am trying to pass a coordinate 0,0). UpdateB is some function. I am getting an error, any ideas what the probl...

How to correctly assign a new String value in C

Hi, i'm trying to understand how to solve this trivial problem in C in the cleanest/safest way: A simple String replacement. Here's my example: #include <stdio.h> int main(int argc, char *argv[]) { typedef struct { char name[20]; char surname[20]; int unsigned age; } person; //Here i can pass s...

sem_t union/struct C++ inherintance

I'm porting some old C++ project on Linux (RHEL 5.3). The situation is the following #include <semaphore.h> class OldClass: public sem_t This used to work because till glibc-2.3.3.20040420 sem_t was a struct. Now, with the newer version of glib is a union =>inheritance not allowed. so the compilation doesn't work. how it was: type...

Is the padding between class members of the same type always the same?

The following class contains some members of the same type: template <typename T> class MyClass { T m0; T m1; T m2; T m3; T m4; //... }; The members are all declared without an intervening access-specifier and thus are allocated that later members have higher addresses (ISO/IEC 14882: 9.2.12). The same paragrap...

Bad pointer type with a typedef

I'm having troubles when calling a function taking a pointer to a string as a parameter. I need to get an Element's name. // method void getStringFromCsv( char ** str ); Let me introduce the structures I'm working with (not written by me and part of a much bigger project, I can't modify them). // typedefs typedef char T_CHAR64[...