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

  • SEARCH
  • Home
  • 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 6762361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:18:52+00:00 2026-05-26T14:18:52+00:00

i dunno where is the problem exactly, but it seems when i pass ‘Memory’

  • 0

i dunno where is the problem exactly, but it seems when i pass ‘Memory’ by reference, it doesn’t work. im trying to Read a Word From Memory in Big Endian and Increment Data by 2

here is how i do it

WORD ReadBigEndianWORD(char **Data)
{
    WORD Result = (unsigned char) *Data[0];
    Result <<= 8;
    Result |= (unsigned char) *Data[1];
    *Data++
    return Result;
}

and i call it like this

char *Memory = ........;
WORD MyWord = ReadBigEndianWORD(&Memory);

the code above doesn’t work (works if Function Argment is ‘char *Data’ and Data passed as ‘Memory’);

and is this the best way to read Big Endian from Memory?

thanks;

  • 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-26T14:18:53+00:00Added an answer on May 26, 2026 at 2:18 pm

    Your code is failing because of the operation precedence of the * operator and the [] operation. The [] has higher precedence, so you need to change your code to:

    WORD ReadBigEndianWORD(char **Data)
    {
        WORD Result = (unsigned char) (*Data)[0];
        Result <<= 8;
        Result |= (unsigned char) (*Data)[1];
        (*Data) += sizeof(WORD);
        return Result;
    }
    

    The line with *Data[0] ends up working correctly because you’re adding an offset of zero. The second *Data[1] will either crash our give you bad data because it’s reading for uninitialized memory. *Data[1] is equivalent to \*(\*(Data + sizeof(char**))), so it’s tacking the the location where Memory is stored and moving past that.

    The best way to see what’s happening is to use your original ReadBigEndianWORD and change the calling code to:

    char *Memory[2] = { "........", ",,,,,,,,," };
    short Myshort = ReadBigEndianshort(Memory);
    

    If you do that you’ll see that *Data[1] is pointing to Memory[1].

    And then to move your Data pointer to the next work you need to increment it by the sizeof a WORD, not the size of char** which is what ++ will do.

    But as everyone else has said you should change your method to take a char* and then worry about moving around in your buffer in the calling code. That will make your function cleaner and clearer.

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

Sidebar

Related Questions

I have a problem i'm trying to read another row in my ResultSet but
Hai am trying to access the aspx variable.But i can't to do this.I dunno
i dunno, but will your machine suffer great slowdown if you use a very
I dunno guys, this is a really weird one, but I might just be
I got some problem with the linked list I've written. I dunno if it's
I have a problem, not that major problem but since i implemented sendMultipartTextMessage on
I've got some code which draws data from an xml file but it seems
i'm stuck with an annoying problem - dunno what's wrong here. my html markup:
I am trying to extract a word that matches a specific pattern from various
I dunno about USA and the UK, but in India, schools still teach GW-BASIC.

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.