Would making plain int 64-bit break a lot of reasonable code?

后端 未结 8 2084
独厮守ぢ
独厮守ぢ 2021-02-19 03:12

Until recently, I\'d considered the decision by most systems implementors/vendors to keep plain int 32-bit even on 64-bit machines a sort of expedient wart. With mo

相关标签:
8条回答
  • 2021-02-19 04:12

    As you say, I think that the promotion rules really are the killer. uint32_t would then promote to int and all of a sudden you'd have signed arithmetic where almost everybody expects unsigned.

    This would be mostly hidden in places where you do just arithmetic and assign back to an uint32_t. But it could be deadly in places where you do comparison to constants. Whether code that relies on such comparisons without doing an explicit cast is reasonable, I don't know. Casting constants like (uint32_t)1 can become quite tedious. I personally at least always use the suffix U for constants that I want to be unsigned, but this already is not as readable as I would like.

    Also have in mind that uint32_t etc are not guaranteed to exist. Not even uint8_t. The enforcement of that is an extension from POSIX. So in that sense C as a language is far from being able to make that move.

    0 讨论(0)
  • 2021-02-19 04:12

    "Reasonable Code"...

    Well... the thing about development is, you write and fix it and then it works... and then you stop!

    And maybe you've been burned a lot so you stay well within the safe ranges of certain features, and maybe you haven't been burned in that particular way so you don't realize that you're relying on something that could kind-of change.

    Or even that you're relying on a bug.

    On olden Mac 68000 compilers, int was 16 bit and long was 32. But even then most extant C code assumed an int was 32, so typical code you found on a newsgroup wouldn't work. (Oh, and Mac didn't have printf, but I digress.)

    So, what I'm getting at is, yes, if you change anything, then some things will break.

    0 讨论(0)
提交回复
热议问题