www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - fputs, stdout

reply Tony <tonytdominguez aol.com> writes:
There is a fputs/stdout in core.stdc.stdio.  std.stdio "public 
imports" that:

"public import core.stdc.stdio;"

Wondering why:

import core.stdc.stdio : fputs;
import core.stdc.stdio : stdout;

void main()
{
    fputs( cast(const char *)"hello world\n",stdout);
}

compiles and runs, but if I change the imports to:

import std.stdio : fputs;
import std.stdio : stdout;

I get this compile error:

fputs_test.d(11): Error: function core.stdc.stdio.fputs (scope 
const(char*) s, shared(_IO_FILE)* stream) is not callable using 
argument types (const(char*), File)
Nov 06 2017
next sibling parent rikki cattermole <rikki cattermole.co.nz> writes:
On 07/11/2017 4:34 AM, Tony wrote:
 There is a fputs/stdout in core.stdc.stdio.  std.stdio "public imports" 
 that:
 
 "public import core.stdc.stdio;"
 
 Wondering why:
 
 import core.stdc.stdio : fputs;
 import core.stdc.stdio : stdout;
 
 void main()
 {
     fputs( cast(const char *)"hello world\n",stdout);
 }
 
 compiles and runs, but if I change the imports to:
 
 import std.stdio : fputs;
 import std.stdio : stdout;
 
 I get this compile error:
 
 fputs_test.d(11): Error: function core.stdc.stdio.fputs (scope 
 const(char*) s, shared(_IO_FILE)* stream) is not callable using argument 
 types (const(char*), File)
core.stdc.stdio : stdout https://github.com/dlang/druntime/blob/master/src/core/stdc/stdio.d#L710 std.stdio : stdout https://github.com/dlang/phobos/blob/master/std/stdio.d#L4662 Answer: not the same thing.
Nov 06 2017
prev sibling parent Jonathan M Davis <newsgroup.d jmdavisprog.com> writes:
On Tuesday, November 07, 2017 04:34:30 Tony via Digitalmars-d-learn wrote:
 There is a fputs/stdout in core.stdc.stdio.  std.stdio "public
 imports" that:

 "public import core.stdc.stdio;"

 Wondering why:

 import core.stdc.stdio : fputs;
 import core.stdc.stdio : stdout;

 void main()
 {
     fputs( cast(const char *)"hello world\n",stdout);
 }

 compiles and runs, but if I change the imports to:

 import std.stdio : fputs;
 import std.stdio : stdout;

 I get this compile error:

 fputs_test.d(11): Error: function core.stdc.stdio.fputs (scope
 const(char*) s, shared(_IO_FILE)* stream) is not callable using
 argument types (const(char*), File)
stdout in core.stdc.stdio and stdout in std.stdio are two different things. In core.stdc.stdio it's a FILE*, and in std.stdio it's std.stdio.File. Basically, core.stdc.stdio gives you the C version, and std.stdio gives you the D version. However, there is no fputs in std.stdio. Rather, std.stdio publicly imports core.stdc.stdio. So, it's the same fputs in core.stdc.stdio, and it expects a FILE*, whereas since you import stdout from std.stdio, you got the File, not the FILE*. So, they're not compatible. - Jonathan M Davis
Nov 06 2017