You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by Brad Nicholes <BN...@novell.com> on 2003/01/10 00:02:15 UTC
apr_atomic_casptr macro (was Re: Showstopper ... was: Tagged
the tree)
The original problem that caused us to have to type cast is the fact
that our compiler complains about the type mismatch between void* and
unsigned long. How does this resolve that issue? It still looks like I
am going to get a type mismatch.
Brad Nicholes
Senior Software Engineer
Novell, Inc., the leading provider of Net business solutions
http://www.novell.com
>>> Brian Pane <br...@cnet.com> Thursday, January 09, 2003
10:44:42 AM >>>
William A. Rowe, Jr. wrote:
>In that case... what about a trick (I believe) Ben Laurie taught us?
>Using a typedef for clarity:
>
>typedef void*(*apr_atomic_casptr_fn_t)(unsigned long* mem, unsigned
long cmp, unsigned long with);
>
>#define apr_atomic_casptr ((apr_atomic_casptr_fn_t)(atomic_cmpxchg))
>
>In this way, the arguments to apr_atomic_casptr will be evaluated in
terms
>of the apr_atomic_casptr_fn_t declaration.
>
>This presumes the arguments exactly match the atomic_cmpxchg function,
>with the exception of twos-compliment signedness.
>
>Make sense?
>
I like the typedef approach, but shouldn't it be
typedef void*(*apr_atomic_casptr_fn_t)(void** mem, const void *cmp,
const void *with);
since casptr operates on pointers rather than ints?
Brian
Re: apr_atomic_casptr macro (was Re: Showstopper ... was:
Tagged the tree)
Posted by "William A. Rowe, Jr." <wr...@rowe-clan.net>.
At 05:02 PM 1/9/2003, Brad Nicholes wrote:
>The original problem that caused us to have to type cast is the fact
>that our compiler complains about the type mismatch between void* and
>unsigned long. How does this resolve that issue? It still looks like I
>am going to get a type mismatch.
The code below shouldn't.
typedef void*(*apr_atomic_casptr_fn_t)(void** mem, const void *cmp, const void *with);
#define apr_atomic_casptr ((apr_atomic_casptr_fn_t)(atomic_cmpxchg))
IFF the stack setup for the atomic_cmpxchg fn and the
apr_atomic_casptr_fn_t typedefs are the same, you are
still using a cast, but applying it to the fn itself. The args
are still evaluated, but in terms of apr_atomic_casptr_fn_t's
declaration ;-)
See how the optional functions behave to get a little bit more
clarity about how/why we've coded functions this way.
Bill