Nagative integer number encode/decode error.

Gary Hai gary@REDACTED
Wed Apr 28 10:05:46 CEST 2010


Is it a bug?

 

Change the code of complex.c list in
http://erlang.org/doc/tutorial/example.html

 

/* complex.c */

#include <stdio.h>

 

int foo(int x) {

  char* p = "abc";

  printf("x-p = %d\n", x-(int)p);

  return x - (int)p;

}

 

int bar(int y) {

  printf("y = %d\n", (-y));

  printf("y = %s\n", (char *)(-y));

  return y;

  //  return y*2;

}

 

Then compile and run the sample as http://erlang.org/doc/tutorial/cnode.html
.

Output of cserver:

$ ./cserver 1234

Node server: [c1@REDACTED][vbox][c1]

test erl_errno:0

Connected to test@REDACTED

x-p = -134597552

y = 134597553

y = bc

 

Output of Eshell V5.7.5

(test@REDACTED)8> AA = complex3:foo(0).

-134597552

(test@REDACTED)9> complex3:bar(AA).

-134597553

 

 

The complex3:bar(AA) should return the same value as AA. But it return the
value decreased 1 to AA.

 

 

Gary Hai



More information about the erlang-questions mailing list