Xref: utzoo comp.lang.c++:11419 comp.std.c++:564 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!julius.cs.uiuc.edu!zweig From: zweig@cs.uiuc.edu (Johnny Zweig) Newsgroups: comp.lang.c++,comp.std.c++ Subject: Add-with-carry operator Message-ID: <1991Feb3.202530.14874@julius.cs.uiuc.edu> Date: 3 Feb 91 20:25:30 GMT Sender: news@julius.cs.uiuc.edu (USENet News) Reply-To: zweig@cs.uiuc.edu Organization: U of Illinois, Dept. of Computer Science, Systems Research Group Lines: 27 In my work with the TCP/IP protocol suite, I have had to implement 16-bit 1's-complement arithmetic in a protable, efficient way for protocol processing modules. In case you're rusty, ones-complement addition is exactly ordinary twos-complement addition with carry (i.e. 101 + 111 = 101 in 3-bit 1's complement since the 1 carried out of the left goes "end around" to the low order bits -- 111 thus is "-0"). Every microprocessor I've ever seen the assembly language instruction set for has, in addition to ordinary twos-complement addition instructions, some kind of "add with carry" instruction which, while not actually implementing ones complement arithmetic (to add A and B in ones complement, you execute A + B add-with-carry 0), is just what the doctor ordered for doing IP checksum computations, and many other iterative ones-complement arithmetic computations. The problem: there is not an add-with-carry operator in C++, so there isn't any way of writing portable code to use this. I know, I know, I know, I can be totally gross and icky and hard and use asm's and come up with a different one for each processor/compiler combination I want to run on. But if there were a standard way of letting the compiler know that I want to do add-with-carry rather than vanilla add I could write portable, efficient code that people like Van Jacobson would think was swell. I suppose that a properly inlined function could do the trick, but it would be nice if there were an operator. Comments? -Johnny Ones