Click here to Skip to main content
16,007,610 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
JokeCaptain Obvious PinPopular
User 238229217-Feb-08 8:05
User 238229217-Feb-08 8:05 
GeneralRe: Captain Obvious Pin
CPallini17-Feb-08 9:44
mveCPallini17-Feb-08 9:44 
GeneralRe: Captain Obvious Pin
StM0n17-Feb-08 10:17
StM0n17-Feb-08 10:17 
GeneralRe: Captain Obvious Pin
leppie18-Feb-08 3:53
leppie18-Feb-08 3:53 
GeneralRe: Captain Obvious Pin
Luc Pattyn19-Feb-08 14:37
sitebuilderLuc Pattyn19-Feb-08 14:37 
GeneralRe: Captain Obvious Pin
Robert Surtees18-Feb-08 4:55
Robert Surtees18-Feb-08 4:55 
GeneralRe: Captain Obvious Pin
Doc Lobster18-Feb-08 5:33
Doc Lobster18-Feb-08 5:33 
GeneralRe: Captain Obvious Pin
PIEBALDconsult18-Feb-08 6:55
mvePIEBALDconsult18-Feb-08 6:55 
Doc Lobster wrote:
Is the result really undefined by ANSI or whoevers specification?


I think i = i++ might be OK, but apparently i = ++1 + 1 is not.

I'm looking in the ISO/IEC 9899:TC2 document, section 6.5 on page 67.

See footnote 71

"
6.5 Expressions

1 An expression is a sequence of operators and operands that specifies computation of a
value, or that designates an object or a function, or that generates side effects, or that
performs a combination thereof.

2 Between the previous and next sequence point an object shall have its stored value
modified at most once by the evaluation of an expression. Furthermore, the prior value
shall be read only to determine the value to be stored.71)

3 The grouping of operators and operands is indicated by the syntax.72) Except as specified
later (for the function-call (), &&, ||, ?:, and comma operators), the order of evaluation
of subexpressions and the order in which side effects take place are both unspecified.

4 Some operators (the unary operator ~, and the binary operators <<, >>, &, ^, and |,
collectively described as bitwise operators) are required to have operands that have
integer type. These operators yield values that depend on the internal representations of
integers, and have implementation-defined and undefined aspects for signed types.

5 If an exceptional condition occurs during the evaluation of an expression (that is, if the
result is not mathematically defined or not in the range of representable values for its
type), the behavior is undefined.

6 The effective type of an object for an access to its stored value is the declared type of the
object, if any.73) If a value is stored into an object having no declared type through an
lvalue having a type that is not a character type, then the type of the lvalue becomes the
effective type of the object for that access and for subsequent accesses that do not modify

71) This paragraph renders undefined statement expressions such as
i = ++i + 1;
a[i++] = i;
while allowing
i = i + 1;
a[i] = i;

72) The syntax specifies the precedence of operators in the evaluation of an expression, which is the same
as the order of the major subclauses of this subclause, highest precedence first. Thus, for example, the
expressions allowed as the operands of the binary + operator (6.5.6) are those expressions defined in
6.5.1 through 6.5.6. The exceptions are cast expressions (6.5.4) as operands of unary operators
(6.5.3), and an operand contained between any of the following pairs of operators: grouping
parentheses () (6.5.1), subscripting brackets [] (6.5.2.1), function-call parentheses () (6.5.2.2), and
the conditional operator ?: (6.5.15).
Within each major subclause, the operators have the same precedence. Left- or right-associativity is
indicated in each subclause by the syntax for the expressions discussed therein.

73) Allocated objects have no declared type.
"
GeneralRe: Captain Obvious Pin
PIEBALDconsult19-Feb-08 10:22
mvePIEBALDconsult19-Feb-08 10:22 
GeneralRe: Captain Obvious Pin
PIEBALDconsult18-Feb-08 6:59
mvePIEBALDconsult18-Feb-08 6:59 
GeneralRe: Captain Obvious Pin
CPallini18-Feb-08 10:25
mveCPallini18-Feb-08 10:25 
JokeRe: Captain Obvious [modified] Pin
User 238229218-Feb-08 18:05
User 238229218-Feb-08 18:05 
GeneralRe: Captain Obvious Pin
CPallini19-Feb-08 2:24
mveCPallini19-Feb-08 2:24 
GeneralRe: Captain Obvious Pin
PIEBALDconsult19-Feb-08 13:50
mvePIEBALDconsult19-Feb-08 13:50 
GeneralRe: Captain Obvious Pin
Brady Kelly18-Feb-08 19:37
Brady Kelly18-Feb-08 19:37 
GeneralRe: Captain Obvious Pin
liquidplasmaflow19-Feb-08 9:43
liquidplasmaflow19-Feb-08 9:43 
GeneralRe: Captain Obvious Pin
Jitse19-Feb-08 10:10
Jitse19-Feb-08 10:10 
GeneralRe: Captain Obvious Pin
liquidplasmaflow19-Feb-08 12:24
liquidplasmaflow19-Feb-08 12:24 
GeneralRe: Captain Obvious Pin
Luc Pattyn19-Feb-08 14:45
sitebuilderLuc Pattyn19-Feb-08 14:45 
GeneralRe: Captain Obvious Pin
liquidplasmaflow20-Feb-08 3:58
liquidplasmaflow20-Feb-08 3:58 
GeneralRe: Captain Obvious Pin
Luc Pattyn20-Feb-08 4:25
sitebuilderLuc Pattyn20-Feb-08 4:25 
GeneralRe: Captain Obvious Pin
PIEBALDconsult20-Feb-08 13:45
mvePIEBALDconsult20-Feb-08 13:45 
GeneralRe: Captain Obvious Pin
Luc Pattyn20-Feb-08 15:37
sitebuilderLuc Pattyn20-Feb-08 15:37 
GeneralRe: Captain Obvious Pin
Megidolaon22-Jun-08 23:37
Megidolaon22-Jun-08 23:37 
GeneralRe: Captain Obvious Pin
User 274316219-Feb-08 21:08
User 274316219-Feb-08 21:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.