POV-Ray : Newsgroups : povray.programming : Object oriented POV scene language? : Re: Object oriented POV scene language? Server Time
28 Jul 2024 16:18:31 EDT (-0400)
  Re: Object oriented POV scene language?  
From: Ron Parker
Date: 24 Jul 2000 10:48:11
Message: <slrn8nomg9.a61.ron.parker@fwi.com>
On 24 Jul 2000 10:37:25 -0400, Ron Parker wrote:
>On 24 Jul 2000 10:22:27 -0400, Warp wrote:
>>  Yes, you can make that code in a #define macro, but the problem is where
>>are you going to the the type for 'tmp'?
>
>Make it one of the parameters to the macro?

Better yet (untested):

#define SWAP(a,b) {                \
  char tmp[sizeof(a)];             \
  assert( sizeof(a) == sizeof(b)); \
  memcpy( tmp, &a, sizeof(a));     \
  memcpy( &a, &b, sizeof(a));      \
  memcpy( &b, tmp, sizeof(a));     \
  }

This does assume that your dialect of C allows you to declare variables
at the start of any block rather than just at the top of the function, 
but I don't see any way of doing it without stipulating that.  It looks
like tmp has a dynamic size, but since sizeof is a compile-time operator,
it really doesn't.

-- 
Ron Parker   http://www2.fwi.com/~parkerr/traces.html
My opinions.  Mine.  Not anyone else's.


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.