Re: Eliminating GCC 3.3 warning

Bob Friesenhahn <[email protected]>
Newsgroups gmane.comp.video.graphicsmagick.core
Message-ID <[email protected]>
By the way, I just tried compiling using these macros under Visual C++
and they crashed and burned.  I suspect it is because I allocated
_magick_mp while I was thinking in C++ mode rather than C mode.

Bob

On Fri, 16 May 2003, Bob Friesenhahn wrote:

> 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
>
> _______________________________________________
> Graphicsmagick-core mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/graphicsmagick-core
>

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



-------------------------------------------------------
This SF.net email is sponsored by: If flattening out C++ or Java
code to make your application fit in a relational database is painful, 
don't do it! Check out ObjectStore. Now part of Progress Software.
http://www.objectstore.net/sourceforge
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.