Input unknown number of integers in a line...

K

Keith Thompson

In the real world (outside of academia and/or newsgroups), anything that
works is "right" (this is a logical extension of "anything that doesn't
work is wrong"). Trust me. I know of what I speak.

It depends on what you mean by "work".

In the real world, many things "work" well enough to pass testing,
only to break, probably at the most inconvenient possible time, in
actual use.

In the case of C code, the standard is a contract between the
programmer and the implementation. If the programmer writes code that
happens to "work", but that violates the contract (e.g., by invoking
undefined behavior), the implementation, or a future one, is under no
obligation to make it continue to work.
 
K

Keith Thompson

Keith Thompson said:
It depends on what you mean by "work".

In the real world, many things "work" well enough to pass testing,
only to break, probably at the most inconvenient possible time, in
actual use.

A concrete example:

#include <stdio.h>
#include <string.h>
int main(void)
{
char before[10];
char message[10];
char after[10];

strcpy(message, "hello, world");
printf("%s\n", message);
return 0;
}

This "works". Is it "right"?
 
C

Chris Croughton

Had I been the inspector, I would also have forbidden
the use of `x * 2' as a substitute for `x >> 1' -- assuming
I was alert that day, of course.

Be a lert, your country needs lerts!

Duh, I meant that he wanted me to write x << 1 instead of x * 2. Which
in fact my error above illustrates why his "approved" code was less
maintainable, I can see the difference between x * 2 and x / 2 much more
easily than between x << 1 and x >> 1 (I have a slight and erratic
right-left aphasia, occasionally I will say one and mean the other --
"no, not that left, the /other/ left!").

Chris C
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,163
Latest member
Sasha15427
Top