On Thu, 2 Dec 2010, Eric Smith wrote:
Note that I do not claim to be a C expert; I am just
skeptical of most
people who claim to be such. I don't expect a C expert to necessarily
know the answer offhand, but they should be able to figure it out. If
they can't, they clearly don't know C anywhere near well enough to be
considered expert, as this problem is based on fundamental principles of
the language.
I'm a rank beginner at C ( <30 years)
I would be worried about the ego of anybody who claims to be expert.
Of course your example would work.
I'm assuming that it was created by mistake, not a deliberate attempt to
print 14 characters from pseudo-random places in memory.
When you shoot yourself in the foot, C has no "gun-control".
What would an excessive optimization compiler change it to?
A[i++] = i++;
Many people think that they know what that will do. They may even be
right for THEIR compiler, but I don't think that even ANSI C is a rigid
enough specification to pin down the sequence of certain actions.
When I taught, I TRIED to get my students to begin to understand that C
will do exactly what you asked for, disunirregardless of what you WANTED.
I also explained to my students that one could optimize for speed,
optimize for object code size, optimize for source code size, optimize for
obfuscation (obfuscated C contest, anyone?), or optimize for readability.
All class assignments were to optimized for readability and thoroughly
commented.
I suggested to them that they should NEVER optimize for speed or size,
until AFTER they had debugged a version optimized for readability, and
even then, seriously consider including the "readable" code as a comment
in their final optimized version.
Very little of what I do/did requires much, if any, speed.
So I am very much NOT an expert on optimization.
--
Grumpy Ol' Fred cisin at
xenosoft.com