Diagnostic required?

  • Thread starter Christopher Benson-Manica
  • Start date
C

Christopher Benson-Manica

Is a conforming C++ implementation required to issue a diagnostic when
invoked on the following code?

#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).
 
J

Jack Klein

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>.
 
C

Christopher Benson-Manica

Jack Klein said:
So there is no guarantee that any other conforming implementation will
compile this successfully, because other implementations might not
include <stdio.h>.

Well, probably none will include <stdio.h>, but they might include
<cstdio> :) Thanks for the answer.
 

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

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top