Click here to Skip to main content
15,888,401 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have custom type called cell and when i try to convert from int to cell i got this strange results:
C++
typedef long int  int32_t;
typedef int32_t   cell;

cell foo()
{
 int xz;
 xz = 150;
 return xz;
}


Expected: 150

Output: 32736 <- why ??? and not 150 as expected.

I hope you will understand this.
Posted
Updated 11-Apr-13 9:23am
v2
Comments
CPallini 11-Apr-13 15:32pm    
Your code does not produce output, how do you check it?
125Azazelo 11-Apr-13 15:39pm    
Outside this code. I use print(). And i know it shod be conversion between type something like
return (cell)xz; but i do not know why this bug heaped. Long int shod be large inapt for int to be stored in whit out conversion.
Sergey Alexandrovich Kryukov 11-Apr-13 16:04pm    
Please, exact code sample, up to the point you got 32736. Use "improve question".
—SA

No, it should return 150 (unless you also redefined int and long int in some weird way :-)).

(By the way, hot did you obtain this output? You did not show the code calling foo(), the problem could be there…)

—SA
 
Share this answer
 
Comments
125Azazelo 11-Apr-13 16:01pm    
Yes i was made a strange define whit int. Thank you for point this.
The following code

typedef long int  int32_t;
typedef int32_t   cell;
#include <stdio.h>
cell foo()
{
 int xz;
 xz = 150;
 return xz;
}

int main()
{
  printf("%ld\n", (long)foo());  /* long int ! */
  return 0;
}


outputs:
150
 
Share this answer
 
v2
Comments
125Azazelo 11-Apr-13 16:02pm    
Thank you for POC i think i got out of my mind.
Sergey Alexandrovich Kryukov 11-Apr-13 16:04pm    
Sure, a 5, for more complete and definitive sample. However, I have no idea what could OP do to obtain 32736, do you (I see that you asked OP)?
—SA
CPallini 11-Apr-13 16:26pm    
I have no idea (though 32736 is interesting).
BTW Thank you.
Sergey Alexandrovich Kryukov 11-Apr-13 17:21pm    
:-)
CPallini 12-Apr-13 4:07am    
@merano: thank you for fixing the mistake.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900