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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:30:02+00:00 2026-06-09T19:30:02+00:00

I am making a C function to integrate into Python that basically creates a

  • 0

I am making a C function to integrate into Python that basically creates a two-dimensional array of chars (each row has constant, known length), reads some data into it, builds a numpy array from it, and returns it to the calling function in Python. I’m not an expert with C, but I believe that in order to preserve the array in memory after exiting the function where it was created, I need to allocate it on the heap with malloc. So I am trying this line:

//rowSize and interleaved are both integers; bytesPerTable is equal to rowSize * interleaved
char arrs[interleaved][rowSize] = (char **)malloc(bytesPerTable * sizeof(char));

Which gives me the compiler error

error: variable-sized object may not be initialized

I’m not sure how to make this work. I want to allocate a block of memory that is the size I need (bytesPerTable) and then organize it into the required two-dimensional array. If I simply declare

char arrs[interleaved][rowSize];

Then it works, but it’s on the stack rather than the heap. Can anyone help?

  • 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-06-09T19:30:04+00:00Added an answer on June 9, 2026 at 7:30 pm

    Do it like this

    char (*arrs)[rowSize] = malloc(bytesPerTable);
    

    arrays can’t be assigned to, pointers and arrays are really different kinds of objects.

    Also:

    • don’t cast the return of malloc
    • sizeof(char) is 1 by definition
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am making a function that turns a list of words into an array
When making a function call in Linux (or OS X for that matter), can
I am making ajax call like this $(document).ready(function() { var abc = new Array();
I'm making a function that multiplies all numbers between an 1 input and a
am making a function that will send me a list of all possible elemnts
I am making a small distance finder applet. Basically, I have two variables coming
I'm making a function in Haskell that halves only the evens in a list
I'm having serious trouble figuring out what is making certain function calls ambiguous and
I've been making some ajax function these days, and I'm facing a small problem.
I making a program and wanted to make an update function... So lets say

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.