Quantcast
Channel: User CPlus - Programming Language Design and Implementation Stack Exchange
Viewing all articles
Browse latest Browse all 66

What are the potential problems with assignment operators returning the new-value operand and how can they be avoided or mitigated?

$
0
0

Inline assignment is when the assignment operator can return the value of the new-value (right-hand) operand. For example:

if ((homedir = getenv("HOME")) == NULL) {    // ...}

I see inline assignment as a hack to make code less redundant. Certainly useful to minimize the number of helper variables that need to be created or evaluating expressions more times than need be. I can also assign multiple items to one value without having to use a variable or repeat the value:

x = y = z = 0;

However, are there downsides to supporting inline assignment? Are there better options for their use cases, such as the aforementioned example?


Viewing all articles
Browse latest Browse all 66

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>