Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 707989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:20:24+00:00 2026-05-14T04:20:24+00:00

I have the following struct: struct Datastore_T { Partition_Datastores_T cmtDatastores; // bytes 0 to

  • 0

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 point to a 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?

Edit: What I mean by zero is that the “values” in the structure are all zeros even after I initialize the structure. The address is not zero, it is the values in the struct that are zero.

Edit: I think I am asking the question wrong. Let’s start over. If I have a struct that is initialized with data, and another object maintains a field member that is a pointer to that struct, if the struct is changed directly:

struct Datastore_T datastores;
char* DatastoreStartAddr = (char*)&datastores;

datastores.cmtDatastores.u16Region[0] = Scheduler.GetMinorFrameCount(); // byte 40,41
datastores.cmtDatastores.u16Region[1] = Scheduler.GetMajorFrameCount(); // byte 42,43

Shouldn’t I be able to access these changes using the DatastoreStartAddr pointer?

EDIT: The following code tries to read the data set in datastores, but using the pointer to the struct:

            CMT_UINT8_Tdef PayLoadBuffer[1500]= {NULL};
            int TDIS = 0;
            int DIS = 0;
            int DSA = 0;

            //copy DataStore info using address and size offsets
            if ((PayLoadBuffer + TDIS + DIS) < IndvDEMMax)
            {
               memcpy((PayLoadBuffer + TDIS), Datastores+DSA, DIS);
               TDIS += DIS;
            }

In the memcpy((PayLoadBuffer + TDIS), Datastores+DSA, DIS) line, Datastores should point to structure and attempts to access an offset in that structure. But since the value is always zero, it copies zero in the PayLoadBuffer.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T04:20:24+00:00Added an answer on May 14, 2026 at 4:20 am

    I don’t know why you are getting an address of zero, but I would guess the code you don’t show has something to do with it. Some other points:

    • Consider using an array of Partition_Datastores_T inside your struct
    • Do not use magic numbers for struct sizes, you want sizeof(Datastore_T )
    • There is no need for the intermediate char*

    Edit: Bobby, to answer your supplementary question – yes you should be able to access it through a pointer, but not through a char * (without jumping through some hoops). You want:

    struct Datastore_T datastores;
    struct Datastore_T * DatastoreStartAddr = &datastores;
    

    and when you use that pointer:

    DatastoreStartAddr->cmtDatastores.u16Region[0] = Scheduler.GetMinorFrameCount(); 
    

    Please note the use of the -> operator.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.