Setting pointers to structs

Posted by Bobby on Stack Overflow See other posts from Stack Overflow or by Bobby
Published on 2010-03-30T13:05:17Z Indexed on 2010/03/30 13:13 UTC
Read the original article Hit count: 234

Filed under:

I have the following struct:

struct Datastore_T
{
    Partition_Datastores_T  cmtDatastores; // bytes 0 to 499
    Partition_Datastores_T  cdhDatastores; // bytes 500 to 999
    Partition_Datastores_T  gncDatastores; // bytes 1000 to 1499
    Partition_Datastores_T  inpDatastores; // bytes 1500 1999
    Partition_Datastores_T  outDatastores; // bytes 2000 to 2499
    Partition_Datastores_T  tmlDatastores; // bytes 2500 to 2999
    Partition_Datastores_T  sm_Datastores; // bytes 3000 to 3499
};

I want to set a char* to struct of this type like so:

struct Datastore_T datastores;

// Elided: datastores is initialized with data here

char* DatastoreStartAddr = (char*)&datastores;
memset(DatastoreStartAddr, 0, 3500);

The problem I have is that DatastoreStartAddr always has a value of zero when it should point to the struct that has been initialized with data.

What am I doing wrong?

© Stack Overflow or respective owner

Related posts about c++