osd7@homxa.UUCP (Orlando Sotomayor-Diaz) (04/21/85)
From: Orlando Sotomayor-Diaz (The Moderator) <cbosgd!std-c> mod.std.c Digest Sun, 21 Apr 85 Volume 5 : Issue 7 Today's Topics: #else JUNK modulus, remainder, and % ---------------------------------------------------------------------- Date: Mon, 15 Apr 85 15:31:33 pst From: nsc!turtlevax!ken@ihnp4.uucp (Ken Turkowski) Subject: #else JUNK To: ihnp4!cbosgd!mark@nsc.uucp >A colleague of mine recently noted their sadness with the (November, 1984) >draft standard's outlawing of source such as > #ifdef VERBOSE > printf("Hello, world.\n"); > #endif VERBOSE >which, according to the draft, must have its last line changed to (for example) > #endif /* VERBOSE */ >to be legal. Such code is now successfully dealt with on many systems. The problem with this is that it removes the ability to structure pre-processor directives. For example, #ifdef VERBOSE # ifdef DEBUG # else !DEBUG # endif DEBUG #else !VERBOSE #endif VERBOSE Indicates clearly which #ifdef is ended with each #endif, regardless of the fact that the stuff after the #else and #endif is ignored. ------------------------------ Date: Mon, 15 Apr 85 15:31:33 pst From: nsc!turtlevax!ken@ihnp4.uucp (Ken Turkowski) Subject: modulus, remainder, and % To: ihnp4!cbosgd!mark@nsc.uucp >The % operator is called the "mod" operator in C, but it does not compute >modulus for signed numbers in any C implementation I know of. When I really >want mod, I have to write (assuming b is unsigned): > > a%b>0?a%b:a%b+b > >Would it break anything to really define % as mod? What's the problem? Both of them are equal (mod b). :-> Seriously, the % operator is defined as the remainder of a division such that: (a / b) * b + (a % b) == a Most implementations define the remainder to have the same sign as the quotient, which has the property that: (-a) / b == -(a / b) Forcing the remainder to be positive would mean that quotient may be one less than it is in most implementations. I think that the objection would not be to defining % to yield a positive number, but to the change in the property of quotients. ------------------------------ End of mod.std.c Digest - Sun, 21 Apr 85 11:19:48 EST ****************************** USENET -> posting only through cbosgd!std-c. ARPA -> ... through cbosgd!std-c@BERKELEY.ARPA (NOT to INFO-C) In all cases, you may also reply to the author(s) above.