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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:38:03+00:00 2026-05-17T17:38:03+00:00

Okay, I am trying to integrate some C code into a C++ project, and

  • 0

Okay, I am trying to integrate some C code into a C++ project, and have run into a few problems. I will detail the first one here.

I keep running into this error:

error: cannot convert ‘char*’ to ‘char**’ in assignment|

here is the offending code (with the breakpoint marked):

char** space_getFactionPlanet( int *nplanets, int *factions, int nfactions )
{
   int i,j,k;
   Planet* planet;
   char **tmp;
   int ntmp;
   int mtmp;

   ntmp = 0;
   mtmp = CHUNK_SIZE;
   tmp = malloc(sizeof(char*) * mtmp); <--- Breakpt

The malloc function is derived from a C header. Here is the declaration:

_CRTIMP void* __cdecl __MINGW_NOTHROW    malloc    (size_t) __MINGW_ATTRIB_MALLOC;

I am using codeblocks, which is set to use MinGW. The above syntax is totally foreign to me.

I am totally stumped, since this code works fine in the C program I took it from.

Any Ideas?

EDIT 1:

Oops, just realized that the declaration is from stdlib.h.

EDIT 2:

I tried:

tmp = static_cast<char **>(malloc(sizeof(char*) * mtmp));

As suggested, but not I get error: invalid static_cast from type ‘char*’ to type ‘char**’.

EDIT 3:

Okay, reinterpret_cast works, but the solution to replace mallocs seems much more elegantly simple, so I am going with that.

However, there is no free(tmp) at the end of the function. Is this a problem if I don’t put in a delete tmp[]?

EDIT 4: I should add that tmp is returned by the function, so it is neccesary to delete tmp, or is this automatic?

Okay I am marking this solved. Thanks for your 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-05-17T17:38:03+00:00Added an answer on May 17, 2026 at 5:38 pm

    If you’re converting to C++, then let’s do away with the malloc shall we?

    tmp = new char*[mtmp];
    

    But later on, you will probably find something like this:

    free(tmp);
    

    Which you need to change to this:

    delete [] tmp;
    

    If tmp is returned from the function, do not delete it. You need to trace the pointer. Somewhere, perhaps in multiple locations, free is going to be called. You need to replace that with delete if you are going with this solution. However, an even better solution would be to ditch the pointers all together, and replace it with a

    vector<string>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay so I have been trying to get into IoC lately. However, I keep
Okay I have been trying to get this to work for some time now.
Okay, so I'm doing my first foray into using the ADO.NET Entity Framework. My
Read EDIT 2 first I am trying to set up some way to visually
Okay, I have a database, but no tables in it. I have some entity
Okay i'm trying to understand WPF and the popular MVVM Pattern. Now i have
Okay, so I have a (SQLite) table called log wherein one column (time) is
Okay, first some background, I can't use any javascript library except YUI for this
Okay we have a single - sign - on and the user will likely
Okay so im working on this php image upload system but for some reason

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.