Re: [Vala] Printfing an object



Here's some code:
---------------
public class Obj : Object {
  public string foo;
}

public void main() {
  var o = new Obj();
  var o1 = new Obj();
  var o2 = new Obj();
  stdout.printf("&o %p\n", &o);
  stdout.printf("&o1 %p\n", &o1);
  stdout.printf("&o2 %p\n", &o2);

  //YAY!!!
  string s = "%p".printf(&o2);
  stdout.printf("o2 with & op: %s\n", s);

  //TEST WITHOUT THE & OPERATOR - The output differs:
  s = "%p".printf( o2 );
  stdout.printf("o2 without & op: %s\n", s);

  s = "%p".printf( o );
  stdout.printf("o without & op: %s\n", s);
}
---------------
On my system I get this output:
&o 0x7fffc55de458
&o1 0x7fffc55de460
&o2 0x7fffc55de468
o2 with & op: 0x7fffc55de468
o2 without & op: 0x153d090
o without & op: 0x153d030


For interest's sake, why is the output from &o different to o? Which would you use as a unique key?

\d


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