Re: Eliminating GCC 3.3 warning

Bob Friesenhahn <[email protected]>
Newsgroups gmane.comp.video.graphicsmagick.core
Message-ID <[email protected]>
Here is a set of macro definitions which seem ok to me. They eliminate
explicit casts (presumably decreasing the opportunity for a bad cast)
and eliminate the new GCC warning. The macros would only be used by
the implementation so there would be no modification to the API.  It
may be that the MagickAllocateMemory macro is a bit "over the top"
since it passes the return pointer type as a macro parameter.  I am
including some sample usages.

#if defined(MAGICK_IMPLEMENTATION)

#define MagickAllocateMemory(type,size) ((type) AcquireMemory(size))

#define MagickFreeMemory(memory) \
{ \
    assert(memory != 0); \
    void *_magick_mp=memory; \
    if (_magick_mp != 0) LiberateMemory(&_magick_mp); \
    memory=0; \
}

#define MagickReallocMemory(memory,size) \
{ \
    assert(memory != 0); \
    void *_magick_mp=memory; \
    ReacquireMemory(&_magick_mp, size); \
    memory=_magick_mp; \
}

#endif /* defined(MAGICK_IMPLEMENTATION) */

/* allocate some memory */
destination=MagickAllocateMemory(char *,strlen(source)+1);

/* free some memory */
MagickFreeMemory(decode);

/* reallocate some memory */
MagickReallocMemory(*destination,strlen(source)+MaxTextExtent);

======================================
Bob Friesenhahn
[email protected]
http://www.simplesystems.org/users/bfriesen



-------------------------------------------------------
Enterprise Linux Forum Conference & Expo, June 4-6, 2003, Santa Clara
The only event dedicated to issues related to Linux enterprise solutions
www.enterpriselinuxforum.com
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.