On Sun, 10 Oct 2004 20:40:09 +0000 (UTC), Christopher Benson-Manica
<at***@nospam.cyberspace.org> wrote in comp.lang.c++:
Is a conforming C++ implementation required to issue a diagnostic when
invoked on the following code?
No.
#include <cstdlib>
#include <iostream>
#include <string>
int main()
{
printf( "Hello, world!\n" ); // oops, <cstdio> missing
return( EXIT_SUCCESS );
}
g++ -Wall -ansi -pedantic does not; I'm wondering if I have cause for
a bug report (assuming one has not yet been submitted).
This is one of the differences between C and C++. The C language
standard specifically forbids any standard header from including any
other standard header. On the other hand, the C++ standard
specifically allows any standard header to include any other standard
header.
So on your particular version of g++, one or more of <csdtlib>,
<iostream>, or <string> includes <stdio.h>. Most likely <iostream>,
but you never know. In which case, no diagnostic is required or even
warranted.
So there is no guarantee that any other conforming implementation will
compile this successfully, because other implementations might not
include <stdio.h>.
--
Jack Klein
Home:
http://JK-Technology.Com
FAQs for
comp.lang.c
http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++
http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html