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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:17:57+00:00 2026-05-28T01:17:57+00:00

I am stuck trying to figure out how to initialize a pointer to a

  • 0

I am stuck trying to figure out how to initialize a pointer to a 3d array inside a 2d structure array. I had it working fine when I could declare the structure like this:

    #define ROUSSEAU      300
    #define OSSO          500
    #define MOJO          9000

typedef struct x_primitive
{  
    short avg[ROUSSEAU][OSSO][MOJO];
} xprimitive;

But unfortunately the structure is too large to declare as a global. So I have to calloc the memory (192GB memory available on the system: win 7 64 bit);

typedef struct x_primitive
{  
    short ***avg;
} xprimitive;

xprimitive **xPmtv, *_xPmtv;


void xallocatePmtvMemory(void)
{
    int structureCount = 10;

    unsigned __int64 pmtvStructureSize =  ROUSSEAU * OSSO * MOJO * sizeof(short);
    unsigned __int64 memoryBlockSize   =   structureCount * pmtvStructureSize;

    _xPmtv = (xprimitive *)  calloc(structureCount, pmtvStructureSize);
    xPmtv  = (xprimitive **) calloc(structureCount, sizeof(xprimitive *));
    for ( int i = 0; i < structureCount; ++i)
    {
        unsigned __int64 index = i * pmtvStructureSize;
        xPmtv[i] = &_xPmtv[ index ];

            // **************** here is the problem  ******
        xPmtv[i]->avg[ROUSSEAU][OSSO][MOJO] =  &_xPmtv[ index + (ROUSSEAU + OSSO + MOJO) ];

    }
}

I am trying to assign the “avg” variable to a chunk of memory, and utterly failing.

  • 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-28T01:17:57+00:00Added an answer on May 28, 2026 at 1:17 am

    Pointers and arrays aren’t interchangeable in the way you seem to be wanting them to be. I think you can probably be doing something much simpler. Make avg into a pointer:

    typedef struct x_primitive
    {  
        short (*avg)[ROUSSEAU][OSSO][MOJO];
    } xprimitive;
    

    And then allocate the space for the array at runtime:

    xprimitive xPmtv;
    
    xPmtv.avg = calloc(1, ROUSSEAU * OSSO * MOJO * sizeof(short));
    

    Using it is a bit funny looking, though:

    (*xPmtv.avg)[1][2][3]
    

    If you have multiple structures, just throw the initialization into a loop. Maybe a better idea is to use a flexible array member to keep the usage syntax looking a bit more normal – it will cost you a dummy entry in the structure – flexible array members aren’t allowed to play around on their own. Then again, why do you have a structure with only one field anyway?

    typedef struct x_primitive
    {
        int   dummyEntry;
        short avg[][OSSO][MOJO];
    } xprimitive;
    

    To allocate one, you’d use:

    xprimitive *xPmtv = calloc(1, sizeof(xprimitive) + ROUSSEAU * OSSO * MOJO * sizeof(short));
    

    And access the array something like:

    xPmtv->avg[1][2][3]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been stuck trying to figure out why a counter cache on my (parent)
I am stuck trying to figure out how to initiate a WSDL connection with
I'm trying to automate file comment headers. I'm stuck trying to figure out how
Im stuck trying to figure out how to pull the information from my pre-populated
I'm stuck again trying to figure out how to out the button clicked to
I'm stuck trying to figure out a solution for the problem below. It's quite
I am stuck trying to figure out how to alter my collision detection to
I am stuck trying to figure out a way of checking if a user
Problem I'm currently stuck trying to figure out what iPhone OS Deployment Target setting
I'm stuck trying to figure out the perl regex to extract the following values:

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.