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 995153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:40:45+00:00 2026-05-16T06:40:45+00:00

I’m posting my first question here after having viewed many useful exchanges by others;

  • 0

I’m posting my first question here after having viewed many useful exchanges by others; it’s very exciting! I’m thinking that this question will be fairly straightforward to answer, but I hope that someone can shed some light on it since its vexing me.

I have a function that accepts an array of bytes passed in as a byte pointer, multiple layers of the program lower. The variable is a member of the class defined as

m_GpsInputBuf[GpsInputBuflen];

The function in question receives a pointer to that array as shown in the code below. The function just shifts the bytes in the array to the left when the checksum for the packet is not validated and another sync character for the data packet is located within the body of the packet. All questions as to the purpose of the function aside though, the point that I’m interested in is the copying of the temp array to the parameter byte array pointer.

The copy to the pPacketbuf variable takes place just as I’d hoped, but when the function terminates, the pPacketbuf variable that exists at the calling level of the ScanAndShift() function is unaffected. This is related to the argument to ScanAndShift() being a copy of the pointer variable, I believe, but I’m too close to the problem to understand it right now. Any insight? Code below:

int CFlirPumpDlg::ScanAndShift(BYTE *pPacketbuf)
{
int idx3 = 0;
BYTE tempGpsInputBuf[GpsInputBuflen];

for(int idx = 1; idx < GpsInputBuflen; idx++)
{
    if(pPacketbuf[idx] == CFlirPumpApp::GPS_Start)
    {
        idx3 = idx;

        for(int idx2 = 0; idx2 < (GpsInputBuflen - idx); idx2++)
        {
            tempGpsInputBuf[idx2] = pPacketbuf[idx3++];
        }

        pPacketbuf = (BYTE *)&tempGpsInputBuf;
        return (GpsInputBuflen - idx);
    }
}

return 0;
}
  • 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-16T06:40:46+00:00Added an answer on May 16, 2026 at 6:40 am

    There are two way to go here.

    1) You allocate a new buffer and populate that with the bytes. For that you need to change your function to take a double pointer like this:

    int CFlirPumpDlg::ScanAndShift(BYTE **pPacketbuf)
    

    But then, you have to allocate a new buffer instead of declaring it. Something like this:

    BYTE* tempGpsInputBuf = malloc(...);
    

    And you have to change this:

    pPacketbuf = (BYTE *)&tempGpsInputBuf;
    

    Into this:

    pPacketbuf = tempGpsInputBuf;
    

    Also all you indexing in pPacketbuf should be done like this:

    *pPacketbuf[index]
    

    And you have to think about freeing the ‘old’ buffer.

    2) You can copy the bytes from tempGpsInputBuf back to pPacketbuf with a memcpy.

    Or you can go with the 3. option and that is to change your algorithm to do all the work in the pPacketbuf. I don’t know if this is possible or not.

    Personally i would go with the 2. or 3. options.

    • 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.