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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:07:22+00:00 2026-05-30T19:07:22+00:00

If I have the memory location of something stored in an integer how can

  • 0

If I have the memory location of something stored in an integer how can I get the object stored at the memory location?

How I need to use this:

#include <stdio.h>
#include "CelGL.h"

/*
 Stride: The size of the data structure containing the per-vertex data
 Offset: Offset within the structure to find this data
 */

// Example structs that store the data
typedef struct {
    float x;
    float y;
    float z;
} Vertex;

typedef struct {
    float x;
    float y;
    float z;
} Normal;

typedef struct {
    float r;
    float g;
    float b;
} Color;

// Info for rendering
typedef struct {
    int vertex;
    int vertexStride;
    int vertexOffset;
    int normal;
    int normalStride;
    int normalOffset;
    int index;
} RenderData;


RenderData _renderData;
int _buffer; // Memory location of array with data

// sets the integer to the memory location of the data
void celBindBuffer(int *buffer)
{
    _buffer = &buffer; // Alert:Incompatible pointer to integer conversion assigning to 'int' from 'int **'
}

void celVertexAttribPointer(CelVertexAttrib attrib, int stride/*bytes*/, int offset/*bytes*/)
{
    switch (attrib) {
        case CelVertexAttribPosition:
            _renderData.vertex = _buffer;
            _renderData.vertexStride = stride;
            _renderData.vertexOffset = offset;
            break;
        case CelVertexAttribNormal:
            _renderData.normal = _buffer;
            _renderData.normalStride = stride;
            _renderData.normalOffset = offset;
        default:
            break;
    }
}

void printVertex(Vertex v)
{
    printf("Vertex[%f,%f,%f]\n", v.x, v.y, v.z);
}

void testPrint(int size/*size in bytes*/)
{
    for (int i = 0; i < size; i++) {
        // Gets the initial location of the data in which it is stored, gets the size of the struct and multiplies it by the index and then offsets to the 
        Vertex v = (Vertex)(_renderData.vertex + i * _renderData.vertexStride + _renderData.vertexOffset); // How can I do this?
        printVertex(v);
    }
}

How am I supposed to get the object at that location, and why am I getting a warning at _buffer = &buffer;?

EDIT:
The variable buffer is an array of structs, not just a single value so I need to have the memory location of it. Once I have that, how can I receive the object at that location (Line:Vertex v = (Vertex)(_renderData.vertex + i * _renderData.vertexStride + _renderData.vertexOffset);)?

EDIT:
So to get the location of the data would I use _buffer = &(*buffer);?

EDIT
Information passed onto method:

typedef struct {
    Vertex position;
    Normal normal;
} VertexData;

static const VertexData mesh[] = {
    {/*v:*/{-0.000000, -1.125000, 0.000000}, /*n:*/{0.059877, -0.998169, 0.007874} },
    {/*v:*/{-0.000000, -0.986528, -0.475087}, /*n:*/{0.114078, -0.863674, -0.490890} },
    {/*v:*/{0.357184, -0.948670, -0.284845}, /*n:*/{0.427045, -0.850368, -0.307321} },
    {/*v:*/{-0.000000, -1.125000, 0.000000}, /*n:*/{0.059877, -0.998169, 0.007874} },
    {/*v:*/{0.357184, -0.948670, -0.284845}, /*n:*/{0.427045, -0.850368, -0.307321} },
    {/*v:*/{0.449795, -0.958029, 0.102663}, /*n:*/{0.477462, -0.877438, 0.045442} },
    {/*v:*/{-0.000000, -1.125000, 0.000000}, /*n:*/{0.059877, -0.998169, 0.007874} },
    {/*v:*/{0.449795, -0.958029, 0.102663}, /*n:*/{0.477462, -0.877438, 0.045442} },
        ...
};

void render() {
    celBindBuffer(mesh);
    celVertexAttribPointer(CelVertexAttribPosition, sizeof(VertexData), offsetof(VertexData, position));
    testPrint(sizeof(mesh) / sizeof(VertexData));
}
  • 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-30T19:07:24+00:00Added an answer on May 30, 2026 at 7:07 pm

    A pointer (int *buffer) is a variable that contains a memory address. Reading the memory at an address pointed by a pointer is called dereferencing a pointer. What you are doing is actually taking an address of the pointer itself. So instead of this:

    _buffer = &buffer;

    .. you have to dereference a pointer to read a value pointed by this buffer pointer:

    _buffer = *buffer;

    I recommend you to read Pointer Basics article, it can help you wrap your head around these things a little bit.

    Hope it helps. Good luck!

    UPDATE:

    In your case, you are better off having a pointer of the same type as the object that is being passed in.. Otherwise it is quite a lot confusing. Here is an example of working with that pointer:

    #include <stdio.h>
    
    typedef struct {
        double x;
        double y;
        double z;
    } Vertex; /* Just to make a simple code compile.. */
    typedef Vertex Normal; /* Same story... */
    
    typedef struct {
        Vertex position;
        Normal normal;
    } VertexData;
    
    static const VertexData mesh[] = {
        { {-0.000000, -1.125000, 0.000000}, {0.059877, -0.998169, 0.007874} },
        { {-0.000000, -0.986528, -0.475087}, {0.114078, -0.863674, -0.490890} },
        { {0.357184, -0.948670, -0.284845}, {0.427045, -0.850368, -0.307321} },
        { {-0.000000, -1.125000, 0.000000}, {0.059877, -0.998169, 0.007874} },
        { {0.357184, -0.948670, -0.284845}, {0.427045, -0.850368, -0.307321} },
        { {0.449795, -0.958029, 0.102663}, {0.477462, -0.877438, 0.045442} },
        { {-0.000000, -1.125000, 0.000000}, {0.059877, -0.998169, 0.007874} },
        { {0.449795, -0.958029, 0.102663}, {0.477462, -0.877438, 0.045442} }
    };
    
    void celBindBuffer(const VertexData *data)
    {
        const Vertex *v0 = &data[0].position;
        const Normal *n0 = &data[0].normal;
    
        const Vertex *v1 = &data[1].position;
        const Normal *n1 = &data[1].normal;
    
        printf("Vertex#1: %f/%f/%f...\n", v0->x, v0->y, v0->z);
        printf("Vertex#2: %f/%f/%f...\n", v1->x, v1->y, v1->z);
    }
    
    int main(void)
    {
        celBindBuffer(mesh);
        return 0;
    }
    

    As you can see, a little bit of pointer arithmetics does the job.
    However, there is a bit of a problem with your function – what you are trying to do is to pass an array of VertexData objects. But the problem is that function celBindBuffer() does not know how many elements are there in that array… You have to pass a number to that function to tells how many elements are there in a vector. Otherwise you can easily run into undefined behavior.

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

Sidebar

Related Questions

How to get the start memory location of a process in c# I have
FlexBuilder's debugger will show you the memory location (or, I can only assume, something
I have a memory block that is divided into a series of location that
Ignoring unsafe code, .NET cannot have memory leaks. I've read this endlessly from many
I have a vector< Object > myvec which I use in my code to
I have this code, but it won't compile and i can't understand what is
I have code that takes a title and an address of a location,then get
Two Windows processes have memory mapped the same shared file. If the file consists
Does gcc have memory alignment pragma, akin #pragma vector aligned in Intel compiler? I
I am trying to load an image in memory but might have memory issues

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.