Aligning pointers to struct

2013-10-02  Source: Original Site  Category:Visual C++  Views:0 

Advertisement

I have two structs and I would like to assign a pointer from t_TMSG to an address in t_TAG.
But the problem is i dont get the correct address.

typedef struct {
WORD tag;
WORD opr;
DWORD unit;
LPCTSTR text;
} t_TAG;

typedef struct {
long tag;
LPCTSTR text;
} t_TMSG;

t_TAG* pTag = SomeFunction(); //assuming pTAg is loaded with values
t_TMSG *pTMsg = (t_TMSG*)(pTag + sizeof(WORD) + sizeof(WORD) ); // i get the wrong address here.

Please help

Related articles
  • Aligning pointers to struct 2013-10-02

    I have two structs and I would like to assign a pointer from t_TMSG to an address in t_TAG. But the problem is i dont get the correct address. typedef struct { WORD tag; WORD opr; DWORD unit; LPCTSTR text; } t_TAG; typedef struct { long tag; LPCTSTR

  • Ubuntu stl vector with data being pointers to structs 2014-01-30

    Is it possible to have a vector with pointers to structs like struct datPoint{ int x; int y; int z; int date; double **data } and then something like vector<*datPoints> vv; but this gives me an error that looks like. runRelate.cpp: In function

  • memory alignment of a struct 2013-03-05

    I heard when define a struct, it is important to make the size of the struct memory aligned. For example, Code:

  • Ubuntu C function pointers in struct 2013-07-05

    Hi, i need some help with function pointers inside a struct in C. I really don't know why i get this errors with this code. #include <stdio.h> #include <stdlib.h> typedef struct { int a,b,s; void (*sum) (func*); void (*af) (func); }func;

  • Ubuntu Pointers and Struct Arrays 2013-07-19

    I'm able to read values from my file into the struct array from within a function using pointers to the array of struct. // code for array of struct // struct CityData { char name[20]; // name of city int pop, // population as of 4/1/2005 popGrow; //

  • qSort: Pointers to Structs 2014-09-11

    I have been searching Google for hours and can't seem to figure this out. I have the following the stuct which contains a lot of different values. Let's say that each struct is about 400 bytes. struct table_row { char name[255]; unsigned int id, stat

  • how to use pointers in struct 2015-01-16

    i dont know if what i did in this program is correct. can you tell me how to use pointers here.thanks! " alt="can someone teach me how to use pointer in this program?? i dont know if what i did in this program is correct. can you tell me how to use p

  • pointers to structs 2012-11-01

    is it possible to create a pointer that points a struct value, like struct person{int name;int age;};person me; person *ptr = me.name; any suggestions on how to do this?

  • basic questions, pointers and structs 2013-02-16

    there, i need some help in understanding pointers. this is an example from school but i cant quite figure i out. i know the basis of pointers but could someone give me some more info. #include <stdio.h>#include <string.h> int string_len(c

  • Ubuntu Pointers to Struct 2013-08-13

    Here is my code: #include <stdio.h> typedef struct { int a; } MYSTRUCTURE; void indirect (MYSTRUCTURE *ns) { MYSTRUCTURE ms = *ns; ms.a = 10; } int main (int argc, char *argv []) { MYSTRUCTURE ms; ms.a = 5; printf ("%d\n", ms.a); indirect (

  • function pointers in struct 2013-10-01

    Was trying to assign a function pointer to a struct member and am getting compile errors. The .h file I have to use has defined the struct: typedef void(*callback)(bool, char*, int, unsigned long, void *); struct CallbackInfo{callback func; void* stu

  • Pointers to struct 2013-10-13

    If I have this struct : typedef struct node {int key;struct node *leftp;struct node *rightp;} *Treep; and I have this function int blah (Treep *tree); How can I pass the tree right pointer again into the blah function, I tried using blah ( tree ->

  • pointers to struct type 2014-06-18

    i have a logic problem with the following code, can anyone help me with the right syntax for getting the information from AirFlag, this is in the struct here is the code: AirFlag contains a number in it and i want amount to count the numbers up. int

  • Multiple definitions of pointers to structs 2014-11-17

    Despite triple checking my code for duplication and checking that the headers include #ifndef I still can't trace what is causing this error message: drawscr.o(.bss+0x0):drawscr.cpp: multiple definition of `massage' main.o(.bss+0x0):main.cpp: first d

  • Dereferencing pointers to structs 2015-06-09

    I have no clue how to dereference a pointer to a struct I got as result of an API call. To explain more detailed, I use the MouseProc Hook within VB where I get as lparam a pointer to a MOUSEHOOKSTRUCT. I also defined a user type in VB that IMHO has

  • malloc to create an array of pointers to a struct 2012-12-28

    how do I create an array of pointers to a struct using malloc? using malloc like this- abc * a = (* abc)malloc(sizeof(abc)*10); I get an array of struct objects. I can access member elements using the "." operator. eg a[2].xxxx what I want is an arra

  • struct alignment 2013-11-25

    Hi I am trying to read a struct from a file using fread() in a C program. Under Solaris/gcc, I have no problems, while using Visual C++, I get problems with alignment. The struct members are mixed int/short,/char and char arrays, and it seems that th

  • Structs in PtrList ? 2012-01-31

    I would like to know how to store pointers to structs in a list or array. For CObject derived classes this can be done with CTypedPtrList or CTypedPtrArray. I guess my problem can be solved by using CPtrList, but I don't know how to declare it !!type

  • C - trying to dynamically allocate an array of structs... 2013-12-30

    Afternoon all, I'm fairly new to programming and new here, so please be gentle..! I'm trying to dynamically allocate an array of structs (actually an array of pointers to structs) and I'm having a world of trouble. This is my attempt so far: file: ar

  • Help with iterators and structs 2014-12-22

    I am trying to use a standard list container inside a struct. In order to free up the list properly I wrote a constructor and destructor for the struct which basically just free's anything in the list. The problem is that it's not compiling under GCC