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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:21:18+00:00 2026-05-31T05:21:18+00:00

I’m working with some really large image cubes that are x * y *

  • 0

I’m working with some really large image cubes that are x * y * z in dimension.

Currently I’ve been dealing with them as such

int ***input = malloc(sizeof(int **)*(lines));
int d;
int i;
for(i = 0 ; i<lines ; i++) {
    input[i] = malloc(sizeof(int *)*bands);

    for(d = 0 ; d<bands ; d++) {
        *input[i][d] = malloc(sizeof(int)*(samples));
    }
}

This has worked fine for me, but now I’m rewriting some of the code and would like to be able to pass the array by reference

I thought to do so required me passing such as foo(&input)

where the function looks like:

foo(int ****input) {
    *input = malloc(sizeof(int **)*(lines));
    int d;
    int i;
    for(i = 0 ; i<lines ; i++) {
        *input[i] = malloc(sizeof(int *)*bands);

        for(d = 0 ; d<bands ; d++) {
            *input[i][d] = malloc(sizeof(int)*(samples));
        }

    }
}

However, I appear to receive seg faults after it enters the first for(i...)` loop.
Any suggestions would be very helpful, thank you.

  • 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-31T05:21:19+00:00Added an answer on May 31, 2026 at 5:21 am

    This is fine when input is the pointer to the 3D vector:

    /* original */
    input[i] = malloc(sizeof(int *)*bands);
    

    When input becomes an int ****: a pointer to the vector pointer, this change is incorrect:

    /* original */
    *input[i] = malloc(sizeof(int *)*bands);
    

    You want:

    /* original */
    (*input)[i] = malloc(sizeof(int *)*bands);
    

    In C, *x[y] means *(x[y]).

    A much simpler thing would be to use a local variable:

    void function(int ****pinput)
    {
      int ***input = malloc(/* ... */);
      /*...code stays the same as before...*/
      *pinput = input; /* place it in the location specified by caller */
    }
    

    Also, let’s make a few stylistic adjustments to the original. (Ignoring the lack of malloc failure checking):

    int ***input = malloc(lines * sizeof *input);
    
    int d;
    int i;
    
    for(i = 0 ; i<lines ; i++) {
        input[i] = malloc(bands * sizeof *input[0]);
    
        /* Noticed an error here: you have *input[i][d] = ... 
           but input[i][d] the pointer to the band;
           *input[i][d] is input[i][d][0]! */
        for(d = 0 ; d<bands ; d++)
            input[i][d] = malloc(samples * sizeof *input[0][0]);
    }
    

    I just took out some unnecessary parentheses and changed the sizeof calculation so that instead of repeating (int **), etc, it is based off the type of the pointer expression being assigned to.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I want use html5's new tag to play a wav file (currently only supported

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.