Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Interger over/under flow in C?

Name: VIPPER 2012-05-01 13:18

Is there a way to implement a portable way of detecting over and underflows in C?

Another thing, my asm code that handles this for now doesnt work either. I cant figure out why not.

asm ("overflow: "
     "xorl %eax, %eax \n"
     "jno O_Ret \n"
     "incl %eax \n"
     "O_Ret: ret\n");

nig_t fuck () {
  nig_t ass = tits + dick;
  if (overflow)
    return piss;
  if (underflow)
    return shit;
  return ass;
}

Now if i could figure out a way for this to work it would only work temporary, as i will need a portable way in the future anyway.

Any help would be appreciated.

Name: Anonymous 2012-05-04 9:01

>>30
it's defined for unsigned types.
It really fucking isn't. Read the standard, dipshit.
6.5.3.3, paragraph 4:

The result of the ~ operator is the bitwise complement of its (promoted) operand (that is, each bit in the result is set if and only if the corresponding bit in the converted operand is not set). The integer promotions are performed on the operand, and the result has the promoted type. If the promoted type is an unsigned type, the expression ~E is equivalent to the maximum value representable in that type minus E.
I dislike morons like you, who have not read The Standard themselves, but kinda heard that it has a lot of undefined behaviour. Most of the things regarding unsigned types are actually well defined.

>>70
a large portion of C is undefined on anything not binary.
Shut the fuck up, moron, you don't understand the meaning of the word "defined".

The C standard defines how C works. When you want to make a C compiler for a ternary computer, you have to implement all arithmetic operations as described in the standard. If you use noncompliant native operations instead, then your compiler is not a C compiler, by definition. Things don't "become undefined" when your compiler sucks, your compiler sucks when your compiler sucks, that is all.

What you wanted to say was that it would be inefficient and kind of pointless to run C code on a ternary computer. If you are too dumb to form and express such a simple idea, and ramble about "things becoming undefined" and other bullshit instead, maybe you shouldn't try to contribute to discussions here.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List