K
Keith Thompson
Harald van Dijk said:Keith Thompson wrote: [...]And on the requirements in any particular case, unless you have a very
narrow definition of "correct". For example, the following program is
perfectly legal (in fact, I believe it's strictly conforming), but
it's not "correct".
#include <stdio.h>
#define SIX 1+5
#define NINE 8+1
int main(void)
{
printf("%d * %d = %d\n", SIX, NINE, SIX * NINE);
return 0;
}
Here's what I meant by correct:
If this is intended to print "6 * 9 = 54", the standard doesn't say that it
does (in fact, it says that it doesn't), so it is then not correct.
If this is intended to print "6 * 9 = 42", the standard says that it does,
so it is then correct.
I think this is not very different from what you mean, but please tell me if
I'm misunderstanding what you consider correct.
I had forgotten that the standard uses the word "correct" in a sense
that differs from the way I've been using it here; thanks to pete for
reminding us.
A program that is correct in all other aspects, operating on
correct data, containing unspecified behavior shall be a correct
program and act in accordance with 5.1.2.3.
(Note that this isn't presented as a definition of the word "correct"
I presume that a program doesn't *have* to contain unspecified
behavior to be considered correct.)
I've been trying to draw a strong distinction between programs that
don't violate the standard and programs that, in addition, actually
work the way they're supposed to.
Going back to what started this, using
#include "stdio.h"
is legal and "correct" in the sense that the standard uses the term,
but it's almost certainly not *right* unless the author actually
intends to allow the program to use a stdio.h header other than the
one provided by the implementation.
It's important to point out that using
#include "stdio.h"
rather than
#include <stdio.h>
is almost certainly a mistake.