swarm-support
[Top][All Lists]
Advanced

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

Strings


From: Glen Ropella
Subject: Strings
Date: Fri, 27 Sep 1996 16:07:20 -0600

I found some peculiar behaviour in which some might be interested.
I'm building strings objects with the createBegin: and
setC:, followed by the appendC:.  My source looks like:

    // come up with a name
    namesize = [uniformRandom rMin: 2 Max: 10];

    // initialize and create the name
    temp_char = [uniformRandom rMin:'A' Max:'Z'];
    name = [String createBegin: [person getZone] ];
    [name setC: (char *) &temp_char];
    [name createEnd];

    // then fill it out
    for (incj = 1; incj <= namesize; incj++) {
      temp_char = [uniformRandom rMin:'a' Max:'z'];
      [name appendC: (char *) &temp_char];
    }

Now, if I declare "temp_char" as a char, then I 
end up with names like the following:

X^Gc^Gg^Gc^g  when it should be Xcgc,
G^El^Eu^Eh^Eu^Eb^Eh^El^Ec^Eg    when it should be Gluhubhlcg,

etc.

However, if I simply declare "temp_char" as an int (i.e.
32-bit), I get names with no trash in them.

The only thing I can figure is that there's trash in the 
"don't care" parts of the word that holds the character and
then the STring methods include that in the mods or creation of
the string.    (Since all 32 bits of "int temp_char" are set with
the return of [uniform ...], the String methods' inclusion of the
unimportant parts of the word is rendered harmless.)

What puzzles me is that the trash is the same for each character
in the same name (always ^E or ^F, never mixed).  The only thing
I can think of to explain that is that I declare temp_char in a
for loop around my object creation, meaning that each time the
loop is entered, temp_char comes back into context, or is re-
declared.

My question now is:  Should this type of thing (making sure
the "don't cares" are zeroed) be taken care of where the 
variable is declared?  Or should it be an inherent part of the
method or function that manipulates the variable?  Or should
it, perhaps, be the compiler's responsibility?

glen

-- 
+-------------------------------------------------------------------------+
|glen e. p. ropella                    |                                  |
|Hive Drone, SFI Swarm Project         |            Hail Eris!            |
|address@hidden                      |                                  |
+-------------------------------------------------------------------------+


reply via email to

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