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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:56:17+00:00 2026-06-08T17:56:17+00:00

In C, is passing a void * as an argument to a free function

  • 0

In C, is passing a void * as an argument to a free function bad practice? If not, how will the function know how much memory to free starting from the location that void * points to?

  • 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-08T17:56:18+00:00Added an answer on June 8, 2026 at 5:56 pm

    free() only needs the start address of the memory block; its contents don’t matter. That’s why it actually has a void* in its signature (so it doesn’t matter what kind of pointer you pass, it will always get a void*).

    The free() function frees the memory space pointed to by ptr, which must have been returned by a previous call to malloc(), calloc() or realloc().

    As you can see you may only free memory allocated by one of these functions – and they store the size of the block internally.


    In case you are curious, the information doesn’t even need to be stored in a separate structure at a single location; for example it’s common for various replacements of the default malloc/free to allocate N+M bytes of memory with M being the size of the metadata struct. At the address returned by that allocation they store their own metadata (such as the allocated size) and then return ptr+M which points to the memory right after the metadata.

    When freeing that memory it can simply subtract M from the address to get the initial pointer, which points to the metadata.

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

Sidebar

Related Questions

When passing an Array Argument to a Function, it's memory address is copied into
warning: passing argument 1 of 'bsearch' makes pointer from integer without a cast and
I'm calling C# method from C++ and passing char** as argument. It has to
I wrote a function containing array as argument, and call it by passing value
I'm having trouble passing a C++0x lambda function as the second argument to makecontext
I'm having a problem passing a variable number of parameters to the function: -(void)addCharacterToScene:(NSString
How can I verify that passing block is execute correctly ? - (void)locationManager:(CLLocationManager *)manager
What is the difference between passing-by-reference and using the C pointer notation? void some_function(some_type&
Passing User defined argument to RPM is possible while installing?. for example: ~>rpm -i
When passing a date from datepicker to sort an excel table, somewhere the format

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.