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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T12:23:37+00:00 2026-05-16T12:23:37+00:00

I have a function which creates an array of pointers. The function which allocates

  • 0

I have a function which creates an array of pointers. The function which allocates the memory returns the new memory pointer through a parameter passed to the function. The simplest code which can reproduce the problem is as follows:

void foo (void** new_mem, size_t bytes)
{
    *new_mem = malloc(bytes);
}

int main (void)
{
    int** ptr_arr; // Want to create an array of pointers

    foo(&ptr_arr, sizeof(int*)*100); // Create an array size of 100
                                     // compiler emits warning: 
                                     // 'void **' differs in levels of indirection from 'int ***'

    return 0;
}

I could cast the first parameter passed to foo like so: ‘(void**)&ptr_arr’ to get rid of the warning, however, I’m wondering: Is there a more appropriate solution?

  • 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-16T12:23:38+00:00Added an answer on May 16, 2026 at 12:23 pm

    Although there’s a guaranteed conversion from int * to void *, there’s no such guarantee for converting from int ** to void **. To think about why this might be, consider that an int * might actually be smaller than a void *. As a result, using a void ** pointer to walk over an array of int *s will walk the wrong stride and get the wrong data. Furthermore, there’s no guarantee that int * will use the same representation as void *, only that there is a way to convert between them.

    In practice, I don’t know of any machines where this will fail. But it’s not guaranteed by the standard.

    EDIT: eek, and what everyone says about passing an int ***. But even if you pass an int **, the above still applies.

    EDIT2: the comp.lang.c FAQ has an excellent discussion about this.

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

Sidebar

Related Questions

I have a function which creates Pointer to a data from a Stream. function
I have C function that takes string pointer as a parameter. This functions returns
All, I have the following array and function, which will create a multidimensional array
I have a function which creates an object of values, but im getting this
I have the following function which creates a std::vector of iterators into another container:
I have a button which creates form elements on click . My addelement function
Using xlwDotNet, I have created a simple function which returns one number. Sometimes, something
I have to create a function that can take in an array of pointers
Hello every one I have made a small function which takes a pointer to
Basically I have a class A which creates an array upon construction. class A

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.