Topic: Headers from the C standard library


Author: Sunil Rao <sunil@raos.demon.co.uk>
Date: 1998/08/27
Raw View
Hello,

Could anyone tell me, please, if the following would be a legal C++ (NOT
C) program, according to the standard????

        #include <stdio.h>

        int main(void)
        {
                printf("hello, world\n");
                return 0;
        }

I'm particularly interested in the header <stdio.h>. Does the standard
still explicitly sanction the use of this header??? Or is it deprecated
or whatever in favour of <cstdio>? I'm a BIT confused regarding this.

Many thanks,

        - sunil

--
"I see you have books under your arm, brother. It is indeed a rare pleasure
these days to come across somebody that still reads, brother."

        - Anthony Burgess


[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: stephen.clamage@sun.com (Steve Clamage)
Date: 1998/08/27
Raw View
Sunil Rao <sunil@raos.demon.co.uk> writes:

>Could anyone tell me, please, if the following would be a legal C++ (NOT
>C) program, according to the standard????

>        #include <stdio.h>

>        int main(void)
>        {
>                printf("hello, world\n");
>                return 0;
>        }

Yes. Perfectly valid.

>I'm particularly interested in the header <stdio.h>. Does the standard
>still explicitly sanction the use of this header??? Or is it deprecated
>or whatever in favour of <cstdio>? I'm a BIT confused regarding this.

For each of the standard C headers of the form <NAME.h>, there
are two standard C++ headers.

1. The header of the form <cNAME> (e.g. <cstdio>) contains
the same declarations found in the standard C header, but
placed in namespace std.

2. The header of the form <NAME.h> (e.g. <stdio.h>) has the
same effect as if <CNAME> were included followed by using-
declarations for each declared type, object, and function.

Example: A possible implementation for <cstdio> could look in
part like this:
 namespace std {
  struct FILE { ... };
  extern FILE* stdout;
  extern "C" int printf(const char*, ... );
  ... // etc
 }
and the <stdio.h> file then could look in part like this:
 #include <cstdio>
 using FILE;
 using stdout;
 using printf;
 ... // etc

Actual implementations might be different, but must wind
up having the same effect if they conform to the standard.

In real life, some current compilers have chosen not to
implement the strict rules yet. AFAIK, all compilers support
the code sample above, whether or not they follow the
standard fully.

--
Steve Clamage, stephen.clamage@sun.com


[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: hinnant@_anti-spam_lightlink.com (Howard Hinnant)
Date: 1998/08/27
Raw View
In article <6s2u5f$e73$1@engnews1.eng.sun.com>, stephen.clamage@sun.com
(Steve Clamage) wrote:

> Sunil Rao <sunil@raos.demon.co.uk> writes:
>
> >Could anyone tell me, please, if the following would be a legal C++ (NOT
> >C) program, according to the standard????
>
> >        #include <stdio.h>
>
> >        int main(void)
> >        {
> >                printf("hello, world\n");
> >                return 0;
> >        }
>
> Yes. Perfectly valid.
>
> >I'm particularly interested in the header <stdio.h>. Does the standard
> >still explicitly sanction the use of this header??? Or is it deprecated
> >or whatever in favour of <cstdio>? I'm a BIT confused regarding this.

Just nitpicking a little bit.  The <name.h> headers are deprecated.  That
means that they are perfectly legal and standard in the current edition of
the standard, but may not be in future editions.  However, I think that
2003 is the very soonest <name.h> would go non-standard, and I personally
doubt it will do so then.

Nevertheless, the intent is that the <name.h> headers are provided for
compatibility with existing code.  The implication here is that new code
should use the <cname> headers.

-Howard


[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: Sunil Rao <sunil@raos.demon.co.uk>
Date: 1998/08/27
Raw View
Howard Hinnant <hinnant@_anti-spam_lightlink.com> wrote, and I reply...
>(Steve Clamage) wrote:
>> Sunil Rao <sunil@raos.demon.co.uk> writes:
>> >Could anyone tell me, please, if the following would be a legal C++ (NOT
>> >C) program, according to the standard????
>>
>> Yes. Perfectly valid.
>
>Just nitpicking a little bit.  The <name.h> headers are deprecated.

Beautiful. Thank you both very much for your clear responses!!!! I'd
suspected this, but I can now be 100% sure.


--
"I see you have books under your arm, brother. It is indeed a rare pleasure
these days to come across somebody that still reads, brother."

        - Anthony Burgess


[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]