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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:12:13+00:00 2026-05-31T19:12:13+00:00

I was never able to fully understand what is going on in the background

  • 0

I was never able to fully understand what is going on in the background of passing pointers in functions and how you use them. Right now Im coding a microprocessor in c. The main goal is to create a snake type game that uses an accelormeter. Needless to say my code is filled with errors dealing with pointer implantation.

Let me try to break it down. First I have an union

    typedef union
{
    UINT8       byte;

    struct
    {
        UINT8   x  : 4;
        UINT8   y  : 4;
    };

} snake;

The union stores the x and y location of a node in the snake. I use this method so when I check if the byte exists I can do it using the byte. Anyway I initialize it as an array “snake location[64]” which is in the main function. I also have int’s of the length and the head and tail of the snake. However trying to pass the union or anything else is where im having the problem. So far my prototypes for the functions are

void randGen(UINT8* x, UINT8* y);
void nextMove(snake* body, int* length, int* head, int* tail);
BOOL setLocation(snake* body,snake temp, int* length, int* head, int*tail, BOOL* newTerm);
void clearLocation(snake* body,snake temp, int* length, int* tail, BOOL* repeat);
void reset(int* length, int* index, UINT8* location);
UINT8 readDirection();
void gameOver();

Here is a snippit of the nextMove function. I pretty much just have more else if statements with more or less the same code so to keep things simple.

void nextMove(snake* body[], int* length, int* head, int* tail){
    UINT8 direction;
    int i;
    snake temp;
    temp = *body[*head];
    do {
    direction = readDirection();
    } while(direction != 4);
    if(direction == 0) { //up
        if(temp.y == 0) gameOver();
        temp.y -= 1;
        for(i = 0; i < *length; i++) {
            if (body[i]->byte == temp.byte) gameOver();
        }
        if(temp.byte == locOfApple.byte) {

        }
        else {
            clearLocation(body, *temp, length, tail, FALSE);
            setLocation(body, *temp, length,head,tail, FALSE);
            *body[*tail] = temp;
            head = tail;
            if(++tail >= length) tail = 0;

        }

    }

Mostly I just need to know how to set the prototype up, how to use the pointer as a value in the function, and what to pass the function. If passing an array (which I believe is different than passing an int) is different, if someone can explain a good way of thinking about it that would really help me grasp this concept.

Any help would be appreciated 🙂

  • 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-31T19:12:14+00:00Added an answer on May 31, 2026 at 7:12 pm

    I figured it out. I needed to setup the union like

    typedef union
    {
        UINT8       byte[64];
    
        struct
        {
            UINT8   x  : 4;
            UINT8   y  : 4;
        }cord[64];
    
    }body;
    

    That allows me to pass it as an array and see all the values.

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

Sidebar

Related Questions

jQuery's deferred's have never liked me, and I've never been fully able to understand
How do I use CSS with RoR? When I link externally, I'm never able
I've never been able to get the Java 6 splash screen to work. I've
I've never been able to find a good script or plugin for sql server
Anyone know this? I've never been able to find an answer.
The project is ASP.NET 2.0, I have never been able to reproduce this myself,
I've had several clients ask this, and I've never been able to get or
I thought I heard that py2exe was able to do this, but I never
I have a column that I need to be able to guarantee never gets
Right now, I have a full screen application which spawns several full screen JFrames

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.