Skarmander wrote On 06/09/06 14:08,:
Kenneth Brody wrote:
(From something brought up on "Help with array/pointer segmentation
fault needed" thread.)
Is "?" a sequence point?
Or, more directly, is the following defined?
/* Will "ptr" be guaranteed to have been assigned before the "?"
* part is evaluated?
*/
foo = ( ( ptr = some_long_expression ) != NULL )
? ptr->bar
: NULL;
What about this?
/* Is the increment of x guaranteed to be complete before the
* "?" part is evaluated?
*/
foo = ( ++x == end ) ? x : y;
Notwithstanding the topical answers given, and the obvious need to know, the
actual answer to this question ought to be "you shouldn't have to be
required to care, so don't do that".
Is there a separate word yet for the incurable urge to cram as much
side-effects into one expression as possible? Somehow "terseness" isn't
descriptive enough.
Personally, I see nothing wrong with
value = (ptr == NULL) ? 0 : ptr->value;
.... and find it easier to read than some of the lengthier
alternatives. Terseness should not be a goal in itself
(although 'tis said "brevity is the soul of wit"), but
neither should verbosity, prolixity, unnecessary redundant
persiflage, wordiness, and verbosity (if you're only half-
brief, you're a half-wit).
A fellow who worked for me once was a native speaker
of one of the agglutinative languages, and had the habit
of jamming many words together to form enormous identifiers.
(How enormous? When we ported the program to a system where
external identifiers were only significant in their first
thirty-two characters, his stuff ran afoul of the limit.)
He was a smart and subtle coder, but his stuff was very
nearly unreadable simply because of the number of characters
you had to digest. His `for' usually required three lines
all to itself and never fewer than two, and no assignment
statement with more than two operators on the r.h.s. could
fit on a single line. Try to read
secondaryFragmentImpactTime = (
sqrt(secondaryFragmentInitialVelocityX
* secondaryFragmentInitialVelocityX
- 4 * secondaryFragmentAccelerationX
* secondaryFragmentImpactOffsetX)
- secondaryFragmentInitialVelocityX)
/ (2 * secondaryFragmentAccelerationX);
.... and ponder whether you'd have preferred to read
t = (sqrt(b*b - 4*a*c) - b) / (2 * a);
Terseness shouldn't be an end, but it's a good means.
--
Er*********@sun.com