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

  • Home
  • SEARCH
  • 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 7083507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:11:12+00:00 2026-05-28T07:11:12+00:00

Came across the following struct which is defined in tcl.h, the C language API

  • 0

Came across the following struct which is defined in tcl.h, the C language API for Tcl.

typedef struct {
char *result;
Tcl_FreeProc *freeProc;
int errorLine;
} Tcl_Interp;

typedef void Tcl_FreeProc(char *blockPtr); 

In the documentation, they have mentioned the following on the struct member fields:

The result field points to the string that represents the result or error message, and the freeProc field tells how to dispose of the storage for the string when it is not needed anymore.

Tcl_SetResult’s freeProc argument specifies how the Tcl system is to manage the storage for the result argument. If Tcl_SetResult or Tcl_SetObjResult are called at a time when interp holds a string result, they do whatever is necessary to dispose of the old string result.

freeProc can take three main values, TCL_STATIC, TCL_DYNAMIC or TCL_VOLATILE.

If freeProc is not one of the values TCL_STATIC, TCL_DYNAMIC, and TCL_VOLATILE, then it is the address of a procedure that Tcl should call to free the string. This allows applications to use non-standard storage allocators.

The fields are defined in the tcl.h header:

#define TCL_VOLATILE ((Tcl_FreeProc *) -1)
#define TCL_STATIC   ((Tcl_FreeProc *) 0)
#define TCL_DYNAMIC  ((Tcl_FreeProc *) free)

What I can’t understand is how they have defined the three values. Shouldn’t it be a function pointer with void return and one char* argument? how can it take values like 0 and -1?

  • 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-28T07:11:13+00:00Added an answer on May 28, 2026 at 7:11 am

    The Tcl_FreeProc is a pointer, as a pointer it can be assigned any value.

    In this case the pointer gets assigned either -1, 0 or a real address and since -1 and 0 are not valid addresses is used to check whether the freeProc points to a function (which needs to be called) or has one of those values and as such no free function is needed.

    EDIT: rephrased it for Chris.

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

Sidebar

Related Questions

I'm going through someone else's code and came across the following syntax: typedef struct
I came across the following weird chunk of code.Imagine you have the following typedef:
I came across the following issue: I have a main simple page on which
I came across the following code on msdn: unsafe static void SquarePtrParam (int* p)
Recently I came across the following snippet, which is an attempt to ensure all
Whilst reading through the DirectWrite source code I came across the following struct: ///
I came across some code containing the following: struct ABC { unsigned long array[MAX];
I came across a difference in speed using the following two structs: public struct
I came across the following code with replaces one variable in a language file
I came across following code function currentSlideFromParams() { var result; if (result = window.location.hash.match(/#([0-9]+)/))

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.