<deane_gavin@hotmail.com> wrote in message
news:1129078861.858088.179870@o13g2000cwo.googlegr oups.com...
[color=blue]
> P.J. Plauger wrote:[color=green]
>> "Branimir Maksimovic" <bmaxa@volomp.com> wrote in message
>> news:1129063580.663342.46100@o13g2000cwo.googlegro ups.com...
>>[color=darkred]
>> > I would not be surprised if cstdio looks like this:[/color][/color]
>
> <snip unlikely contents of cstdio>
>[color=green][color=darkred]
>> > or:
>> > #include <stdio.h>
>> > namespace std{
>> > using printf;
>> > // ......
>> > }[/color]
>>
>> That also doesn't conform exactly to the C++ Standard, but
>> it's a widely adopted practice. It'll probably be made
>> valid in the next release of the C++ Standard.[/color]
>
> Have I misunderstood something here - is the following a correct
> program?
>
> #include <cstdio>
>
> int main()
> {
> printf("Hello world\n"); // or should that be std::printf?
> }[/color]
Should be std::printf, but it sometimes works anyway.
[color=blue]
> I always thought that <cstdio> should put its names in the std
> namespace only - not in the global namespace as well. 17.4.1.2/4 would
> seem to confirm that. But Comeau online, for example, compiles my
> program.[/color]
You're correct about what the C++ Standard *says*. What most
implementations *do* is another matter. And that's because
the C++ committee repeatedly refused to listen to compiler
vendors while drafting the C++ Standard. (Don't forget export
either.)
[color=blue]
> Because the
>
> #include <stdio.h>
> namespace std{
> using printf;
> // ......
> }
>
> approach is so widespread I have never been keen to use the <cname>
> headers instead of <name.h>. If the compiler is likely to let me get
> away with including <cstdio> but leaving the std:: off the front of
> printf I might as well use <stdio.h> and have a correct program. But if
> <cstdio> is allowed to put its names in the global namespace as well as
> the std namespace, I'm worrying over nothing.[/color]
You need to distinguish between what might happen and what you can
rely on. The safe rules are:
-- If you want assuredly to be able to write std::printf, include
<cstdio>.
-- If you want assuredly to be able to write ::printf, include
<stdio.h>.
The C++ Standard says that <cstdio> will not declare ::printf
and that <stdio.h> will also declare std::printf, but neither
of these rules is consistently followed in real life.
HTH,
P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com