swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Swarm-Support] puzzlng question about message passing and types


From: Jakson A. Aquino
Subject: Re: [Swarm-Support] puzzlng question about message passing and types
Date: Mon, 27 Feb 2006 14:10:47 +0000

On Mon, Feb 27, 2006 at 02:59:51PM +0930, paul box wrote:
> Since Rainfall is a double, the last command in makeItRain should read
>   [cellList forEach: M(addRain:): rainfall]
>
> but that will not compile, for obvious reasons (incompatible type for
> argument 2 of 'forEach::')
>
> However, casting the number as an integer, passing it to
> Cell_addRain() , and having Cell_addRain() accept it as a double seems
> to work fine (compiles and runs, with Cells receiving and storing
> correct numbers).  I find this very disturbing.  Why would that work?
> And is there a more "honest" way to make it work?

According to swarm documentation "any non-id value must be
cast to the id type". If you cast it to the int type
probably your code will not be portable to 64 bit systems.
In 32 bit systems the sizeof(int) = 4 = sizeof(pointer),
but, for example, I'm running an amd64 where the
sizeof(double) = 8 = sizeof(pointer).

Alternatively, you could change makeItRain to (not tested):

-makeItRain {

  double rainfall;
  id index;
  Cell *c;

  // rainGen is a LogNormalDist object, which returns double numbers
  rainfall = [rainGen getDoubleSample];
 // printf ("rainzone %d dumping %g mm of rain\n", rainzoneID, rainfall);
 index = [cellList begin: [self getZone]];
 while ((c = [index next])) {
   [c addRain: rainfall];
 }
 [index drop];

  return self;
}

I'm a beginner with swarm, and you still might receive better
commentaries to your post.

Best regards,

Jakson



reply via email to

[Prev in Thread] Current Thread [Next in Thread]