Categories:

.NET (357)

C (330)

C++ (183)

CSS (84)

DBA (2)

General (7)

HTML (4)

Java (574)

JavaScript (106)

JSP (66)

Oracle (114)

Perl (46)

Perl (1)

PHP (1)

PL/SQL (1)

RSS (51)

Software QA (13)

SQL Server (1)

Windows (1)

XHTML (173)

Other Resources:

There seem to be a few missing operators ..

Q

There seem to be a few missing operators, like ^^, &&=, and ->=.

✍: Guest

A

A:A logical exclusive-or operator (hypothetically ``^^'') would be nice, but it couldn't possibly have short-circuiting behavior analogous to && and || Similarly, it's not clear how short-circuiting would apply to hypothetical assignment operators &&= and ||=. (It's also not clear how often &&= and ||= would actually be needed.)

Though p = p->next is an extremely common idiom for traversing a linked list, -> is not a binary arithmetic operator. A hypothetical ->= operator therefore wouldn't really fit the pattern of the other assignment operators.

You can write an exclusive-or macro in several ways:

#define XOR(a, b) ((a) && !(b) || !(a) && (b)) /* 1 */

#define XOR(a, b) (!!(a) ^ !!(b)) /* 2 */

#define XOR(a, b) (!!(a) != !!(b)) /* 3 */

#define XOR(a, b) (!(a) ^ !(b)) /* 4 */

#define XOR(a, b) (!(a) != !(b)) /* 5 */

#define XOR(a, b) ((a) ? !(b) : !!(b)) /* 6 */

The first is straight from the definition, but is poor because it may evaluate its arguments multiple times The second and third ``normalize'' their operands to strict 0/1 by negating them twice--the second then applies bitwise exclusive or (to the single remaining bit); the third one implements exclusive-or as !=. The fourth and fifth are based on an elementary identity in Boolean algebra, namely that

_ _
a (+) b = a (+) b

(where (+) is exclusive-or and an overbar indicates negation). Finally, the sixth one, suggested by Lawrence Kirby and Dan Pop, uses the ?: operator to guarantee a sequence point between the two operands, as for && and ||. (There is still no ``short circuiting'' behavior, though, nor can there be.)

2015-01-28, 1223👍, 0💬

Popular Posts:

How To Return Top 5 Rows? - MySQL FAQs - SQL SELECT Statements with JOIN and Subqueries If you want ...

How To Enter Boolean Values in SQL Statements? - MySQL FAQs - Introduction to SQL Basics If you want...

when should the volatile modifier be used? The volatile modifier is a directive to the compiler's op...

How To Create an Add-to-My-Yahoo Button on Your Website? - RSS FAQs - Adding Your Feeds to RSS News ...

Regarding C Coding Given: Line in file Contents 30 int * someIDs, theFirst, *r; 110 someIDs =GetSome...