FREE

Charles Hannum CMH117 at psuvm.psu.edu
Tue Feb 27 05:17:54 AEST 1990


Why don't you try:

  #define  NE_ARR_MALLOC(n)  ((y *)calloc(n, sizeof(y)))
  #define  NE_ARR_FREE(x)    (free(x), x=NULL)


In your original posting, you were trying to pass the length of x (which is
the size of the pointer) to free().  This won't work.  You should just pass
x itself.

Also, your use of a block structure in NE_ARR_FREE points out a disturbing
problem in C.  If I have something like:

   if (conda)
      definea(junk);
   else
      defineb(junk);

Will work fine if definea() and defineb() are either functions or single-line
#defines.  But what about multiple-line #defined macros?  In this case, you
can work around it with the , operator, but in many cases you cannot.

For compilers that support inline function calls (read: macros that look like
functions) that would be the best solution.  But with those that don't ...


Virtually,
- Charles Martin Hannum II       "Klein bottle for sale ... inquire within."
    (That's Charles to you!)     "To life immortal!"
  cmh117 at psuvm.{bitnet,psu.edu}  "No noozzzz izzz netzzzsnoozzzzz..."
  c9h at psuecl.{bitnet,psu.edu}    "Mem'ry, all alone in the moonlight ..."



More information about the Comp.lang.c mailing list