strange ints


    Aug 31 2006 | 5:10 pm
    I'm a little bit confused with a newbie pointer problem...If i send a
    message "mode 1 1 1" to this :
    void myobj_mode(t_myobj *x, Symbol *s, int ac, Atom *av)
    {
    if (ac==3)
    {
    t_atom list[3];
    SETLONG(list+0, av);
    SETLONG(list+1, av+1);
    SETLONG(list+2, av+2);
    outlet_list(x->m_ob.o_outlet,ps_list,3,list);
    }
    it doesn't output '1 1 1' but '1240418 1240424 1240430'... why ?
    f.e
    --
    f.e chanfrault | aka | personal computer music
    > >>>>>> http://www.personal-computer-music.com
    > >>>>>> |sublime music for a desperate people|

    • Aug 31 2006 | 5:18 pm
      f.e wrote:
      > I'm a little bit confused with a newbie pointer problem...If i send a
      > message "mode 1 1 1" to this :
      >
      > void myobj_mode(t_myobj *x, Symbol *s, int ac, Atom *av)
      > {
      > if (ac==3)
      > {
      > t_atom list[3]; SETLONG(list+0, av);
      > SETLONG(list+1, av+1);
      > SETLONG(list+2, av+2);
      > outlet_list(x->m_ob.o_outlet,ps_list,3,list);
      > }
      >
      > it doesn't output '1 1 1' but '1240418 1240424 1240430'... why ?
      Because you want to set a LONG but set the t_atom as value... so you end
      up with the stuff at the address of av+i being represented as long...
      In case you're sure to get ints only, you can copy input t_atoms to
      output t_atoms directly, otherwise check for ints first (av[i].a_type ==
      A_LOMG) and access the int value using av[i].a_w.w_long. So in the end
      it should read:
      SETLONG(list+1, av[1].a_w.w_long);
      which euqals to:
      list[1] = av[1]
      Olaf
    • Aug 31 2006 | 5:18 pm
      On Aug 31, 2006, at 10:10 AM, f.e wrote:
      > I'm a little bit confused with a newbie pointer problem...If i send
      > a message "mode 1 1 1" to this :
      >
      > void myobj_mode(t_myobj *x, Symbol *s, int ac, Atom *av)
      > {
      > if (ac==3)
      > {
      > t_atom list[3]; SETLONG(list+0, av);
      > SETLONG(list+1, av+1);
      > SETLONG(list+2, av+2);
      > outlet_list(x->m_ob.o_outlet,ps_list,3,list);
      > }
      >
      > it doesn't output '1 1 1' but '1240418 1240424 1240430'... why ?
      SETLONG() assumes it is being passed a long integer, but av is an
      *atom* pointer. If you want the long from within the atom pointer you
      need to retrieve it somehow. e.g... av->a_w.w_long, or atom_getlong(av);
      Or you could just copy the atoms directly, e.g. list[0] = av[0];
      -Joshua
    • Aug 31 2006 | 5:20 pm
      Thanks a lot to both of you :-)
      best
      f.e
      f.e chanfrault | aka | personal computer music
      > >>>>>> http://www.personal-computer-music.com
      > >>>>>> |sublime music for a desperate people|
      Joshua Kit Clayton wrote:
      >
      > On Aug 31, 2006, at 10:10 AM, f.e wrote:
      >
      >> I'm a little bit confused with a newbie pointer problem...If i send a
      >> message "mode 1 1 1" to this :
      >>
      >> void myobj_mode(t_myobj *x, Symbol *s, int ac, Atom *av)
      >> {
      >> if (ac==3)
      >> {
      >> t_atom list[3]; SETLONG(list+0, av);
      >> SETLONG(list+1, av+1);
      >> SETLONG(list+2, av+2);
      >> outlet_list(x->m_ob.o_outlet,ps_list,3,list);
      >> }
      >>
      >> it doesn't output '1 1 1' but '1240418 1240424 1240430'... why ?
      >
      >
      > SETLONG() assumes it is being passed a long integer, but av is an
      > *atom* pointer. If you want the long from within the atom pointer you
      > need to retrieve it somehow. e.g... av->a_w.w_long, or atom_getlong(av);
      >
      > Or you could just copy the atoms directly, e.g. list[0] = av[0];
      >
      > -Joshua
      >