sawyl: (Default)
[personal profile] sawyl
Whilst trying to resolve various bugs in a piece of third party code, I came across an interesting data typing problem, exemplified by the following snippet of code:

void foo(size_t *f) { *f = 1; }

int main() { long l = 0; int i = 0; arch(); foo((size_t *)&l); foo((size_t *)&i); printf("l = %ld (size = %d)\n" "i = %ld (size = %d)\n", l, sizeof(long), i, sizeof(int)); }

This works as expected on the Intel platforms (using both gcc and vendor compilers):

machine: i686 l = 1 (size = 4) i = 1 (size = 4)

And:

machine: ia64 l = 1 (size = 8) i = 1 (size = 4)

But, wouldn't you know it, it behaves differently on my target platform:

machine: SX-6 l = 4294967296 (size = 8) i = 1 (size = 4)

So, my question is, which behaviour is correct? The behaviour on Intel or on the SX? The former, I suspect. I'm desperately hoping that there's some sort of compiler flag that I can use to fix the problem on the SX because I really, really don't want to have recode — the application is riddled with this stuff.

This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

Profile

sawyl: (Default)
sawyl

August 2018

S M T W T F S
   123 4
5 6 7 8910 11
12131415161718
192021222324 25
262728293031 

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Feb. 5th, 2026 10:32 am
Powered by Dreamwidth Studios