12,241,564 members (55,298 online)
Rate this:
See more:
I have custom type called cell and when i try to convert from int to cell i got this strange results:
```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 11-Apr-13 10:20am
Edited 11-Apr-13 10:23am
v2
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

Rate this:

## Solution 1

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
125Azazelo 11-Apr-13 16:01pm

Yes i was made a strange define whit int. Thank you for point this.
Rate this:

## Solution 2

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`
v2
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.

Top Experts
Last 24hrsThis month
 OriginalGriff 545 Sergey Alexandrovich Kryukov 475 Dave Kreskowiak 340 F-ES Sitecore 280 Afzaal Ahmad Zeeshan 275
 OriginalGriff 9,918 F-ES Sitecore 5,058 Jochen Arndt 4,468 Dave Kreskowiak 4,318 Richard MacCutchan 4,061