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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:51:49+00:00 2026-05-16T01:51:49+00:00

I have a function which reallocs a pointer given as an argument to a

  • 0

I have a function which reallocs a pointer given as an argument to a new size. Now, the problem is that – according to the man page – realloc needs a pointer which has been returned by malloc or calloc before.

How can I make sure that the caller passes a pointer that meets those requirements?
There seem to be no build-in C mechanics (like type qualifiers or something) to do so.

Now, before I restructure my API (as I consider the function as it is now not to be robust enough) – can you please verify that I haven’t missed something?

Thanks in advance.

Edit:
One solution would obviously be to malloc in the function. The problem with that is that the caller does not “see” the allocation. Thus I would need to explictly say in the docs that he has to free the pointer. That’s even worse than to expect them to provide a malloc’d pointer (which would imply that the caller has to free it).

What I really want is something that blocks abuse at compile time. That, and a pony. 😉

  • 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-16T01:51:49+00:00Added an answer on May 16, 2026 at 1:51 am

    How can I make sure that the caller passes a pointer that meets those requirements?

    Documentation.

    Define the API.

    If the person writing the caller refuses to follow the API, things crash. They refused to play by your rules and things crashed. What did they expect?

    • 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 takes an argument that is used in where clause
i have function which return list as given below. List<User> lstUsers = SearchUsers(searchText); which
I have a function which looks like this. function loadbottom(){ $(#uploadsegment).load(bottompart.php?id=<?php echo $_GET['id'] ?>&page=<?php
I have a function which creates Pointer to a data from a Stream. function
I have function getMemory() which returns VARIANT (mfc). It is said that in ulVal
I have one template function which will take a pointer type and i have
I have function bar which I need to call. I'm new to using callbacks,
I have this function which removes occurrences of a given element within the list
hi i have function which is called by tinker listbox so i cannot return
Can I´m asking for advice. I have function which should return javascript object function

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.