Shortened version of STRCPY()-- where does it test for NULL ?
Discuss Shortened version of STRCPY()-- where does it test for NULL ? in the C Programming forum on Dev Shed. Shortened version of STRCPY()-- where does it test for NULL ? C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
Time spent in forums: 1 Month 4 Days 5 h 19 m 36 sec
Reputation Power: 1801
In C assignment is an expression rather than a statement. That is to say it has a result value like any other expression.
The result of an assignment expression is the value of the right-hand-side. It is this attribute that allows expresions such as:
a = b = c = d = 0 ;
In your case the loop terminates when *t++ is zero - i.e. when the next character in the source string is nul.
Originally Posted by C learner
Also, what is the exact priority of the operators in the second case:
The mere fact that you have to ask is one good reason not to write expressions like that. It may be "clever" but it is not "smart". It has its place perhaps in library code but clarity is not served by such expressions.
The honest answer is I don't know, but to find out would be simple enough but not effective use of my time. It is sufficient to realise that the the rules are arcane and often undefined, so the truly smart programmer avoids the issue altogether and never uses ++ or -- (post or pre) in an expression where other operators are involved. So essentially restricting use to:
Brian Kernighan said this:
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
Last edited by clifford : July 28th, 2013 at 07:02 AM.