Re: why not use signed ints in c?

2013-06-21 Thread Thorsten Glaser
oneofthem dixit:

If you shouldn't use signed ints, then how do store negative numbers?

Basically, if you have something negative, you store it
either in a signed int, or in a typedef union {
mksh_ari_t i;
mksh_uari_t u;
} mksh_ari_u;

(where ari_t and uari_t are the signed and unsigned ints,
respectively), and do all arithmetics on it by using the
unsigned access, and do comparisons (other than == and !=)
and printing using the signed access.

This is legal in POSIX, and in C as long as the system uses
two’s complement. I was told that people arguing against this
have yet failed to show a workable C implementation on a system
not using two’s complement, so… fine.

bye,
//mirabilos
-- 
13:37⎜«Natureshadow» Deep inside, I hate mirabilos. I mean, he's a good
guy. But he's always right! In every fsckin' situation, he's right. Even
with his deeply perverted taste in software and borked ambition towards
broken OSes - in the end, he's damn right about it :(! […] works in mksh


Re: why not use signed ints in c?

2013-06-20 Thread Thorsten Glaser
oneofthem dixit:

Wow, thanks. I didn't expect such an in depth response.

You’re welcome ☺

I hope that this response will show up on search engines
and help other coders, too, that’s why it was a tad lengthy.

I think it can be extended even, e.g. with actual examples
plus citations of the ISO C rules in question… this was
meant as an intro/oversight/reasoning only. Maybe someone
will follow up in the future ☺ I’m sure there are language
gurus around somewhere. Or maybe someone else will just be
happy to have discovered this topic and be angered at GCC
just the same ;-)

bye,
//mirabilos
-- 
“It is inappropriate to require that a time represented as
 seconds since the Epoch precisely represent the number of
 seconds between the referenced time and the Epoch.”
-- IEEE Std 1003.1b-1993 (POSIX) Section B.2.2.2