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.

Date: 2007-03-21 10:23 am (UTC)
From: [identity profile] doctor-squale.livejournal.com
You guys don't read the manuals, do you ? :)

sxmpic++ -size_t64

Date: 2007-03-21 09:40 pm (UTC)
From: [identity profile] sawyl.livejournal.com
If we read the manuals, we wouldn't need application analysts, would we...

Date: 2007-03-21 10:44 pm (UTC)

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 05:48 pm
Powered by Dreamwidth Studios