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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T05:16:34+00:00 2026-05-15T05:16:34+00:00

What is the C equivalent of C++ delete[] (char *) foo->bar; Edit: I’m converting

  • 0

What is the C equivalent of C++

delete[] (char *) foo->bar;

Edit: I’m converting some C++ code to ANSI C. And it had:

typedef struct keyvalue
{
  char *key;
  void *value;
  struct keyvalue *next;
} keyvalue_rec;

// ...

  for (
    ptr = this->_properties->next, last = this->_properties;
    ptr!=NULL;
    last = ptr, ptr = ptr->next)
  {
    delete[] last->key;
    delete[] (char *) last->value;
    delete last;
  }

Would this do it for C?

free(last->key);
free(last->value);
free(last)
  • 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-15T05:16:35+00:00Added an answer on May 15, 2026 at 5:16 am

    In C, you don’t have new; you just have malloc(); to free memory obtained by a call to malloc(), free() is called.

    That said, why would you cast a pointer to (char*) before passing it to delete? That’s almost certainly wrong: the pointer passed to delete must be of the same type as created with new (or, if it has class type, then of a base class with a virtual destructor).

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

Sidebar

Related Questions

What's the equivalent of new/delete of C++ in C? Or it's the same in
is there an equivalent of oracle's rowid in mysql? delete from my_table where rowid
shutil.rmtree will not delete read-only files on Windows. Is there a python equivalent of
What would be the PHP equivalent to this code, I have tried curl but
I would like to implement something equivalent to the unix command 'rm foo*' using
I'm wondering if Code Igniter has something equivalent to a small framework I built,
I have some code that produces a set of primary key values that I
I want to do the moral equivalent of the following VBA code: For Each
guys can you help me with my code.. i want to edit a specific
Currently I have some code deleting some temporary files created by my program: #

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.