www.digitalmars.com         C & C++   DMDScript  

D - Something wrong in std.c.stdio.d Linux version

reply =?ISO-8859-1?Q?Julio_Jim=E9nez?= <jujibo inicia.es> writes:
//program 1.d

import std.c.stdio;


void main()
{
   printf("Press a key to continue...\n");
   char a = getchar();
   printf("Ok\n");
}

compile and run ok...

but

import std.c.stdio;


void main()
{
   printf("Press a key to continue...\n");
   char a = getch();
   printf("Ok\n");
}

output:

gcc 1.o -o 1 -g -lphobos -lpthread -lm
1.o(.gnu.linkonce.t_Dmain+0xf): En la función `_Dmain':
: undefined reference to `getch'
collect2: ld devolvió el estado de salida 1

some functions in stdio.d not in Linux, like:

int	 getch();
int	 getche();
int      kbhit();

I can find getch() at curses.h no match for getche() and kbhit()......

I think that functions may be declared in the way:

version (Win32)
{
	int	 getch();
	int	 getche();
	int      kbhit();
}

Is that correct?


regards


Julio Jiménez
Mar 12 2004
parent reply "news.digitalmars.com" <jcesar phreaker.net> writes:
Probably you'll need to link against libncurses.a.


"Julio Jiménez" <jujibo inicia.es> escribió en el mensaje
news:c2s0nk$5o1$1 digitaldaemon.com...
 //program 1.d

 import std.c.stdio;


 void main()
 {
    printf("Press a key to continue...\n");
    char a = getchar();
    printf("Ok\n");
 }

 compile and run ok...

 but

 import std.c.stdio;


 void main()
 {
    printf("Press a key to continue...\n");
    char a = getch();
    printf("Ok\n");
 }

 output:

 gcc 1.o -o 1 -g -lphobos -lpthread -lm
 1.o(.gnu.linkonce.t_Dmain+0xf): En la función `_Dmain':
 : undefined reference to `getch'
 collect2: ld devolvió el estado de salida 1

 some functions in stdio.d not in Linux, like:

 int getch();
 int getche();
 int      kbhit();

 I can find getch() at curses.h no match for getche() and kbhit()......

 I think that functions may be declared in the way:

 version (Win32)
 {
 int getch();
 int getche();
 int      kbhit();
 }

 Is that correct?


 regards


 Julio Jiménez
Mar 12 2004
parent reply =?ISO-8859-1?Q?Julio_Jim=E9nez?= <jujibo inicia.es> writes:
news.digitalmars.com wrote:
 Probably you'll need to link against libncurses.a.
 
 
Yes, I know it... (I can use any C library writing my own interface). But that's not what i'm talking... int getch(); int getche(); int kbhit(); Not defined in linux stdio.h and are included in std.c.stdio. That's why i suggest to define only for windows version regards Julio Jiménez
Mar 12 2004
parent reply "Matthew" <matthew stlsoft.org> writes:
I'd wondered about that myself some time ago. Didn't come up with any
conclusion though ...

"Julio Jiménez" <jujibo inicia.es> wrote in message
news:c2sfnv$v97$1 digitaldaemon.com...
 news.digitalmars.com wrote:
 Probably you'll need to link against libncurses.a.
Yes, I know it... (I can use any C library writing my own interface). But that's not what i'm talking... int getch(); int getche(); int kbhit(); Not defined in linux stdio.h and are included in std.c.stdio. That's why i suggest to define only for windows version regards Julio Jiménez
Mar 12 2004
parent reply lord.vegeta ica.luz.ve writes:
It has been a long time since the last time I programmed something in C for
windows/dos, but the functions getch(), getche() and kbhit() were always
declared in a 
compiler specific conio.h and not in stdio.h. The C standard does
not include those 
functions in stdio.h. 
In curses or ncurses for unix there
are  equivalent functions, but they do not 
necessarily have the same names and
certainly they aren't in stdio.h. 
 
 
In article
<c2sj04$1503$1 digitaldaemon.com>, Matthew says... 
 
I'd wondered about that
myself some time ago. Didn't come up with any
conclusion though ... 

"Julio Jiménez" <jujibo inicia.es> wrote in message 
news:c2sfnv$v97$1 digitaldaemon.com... 
 news.digitalmars.com wrote: 
 Probably you'll need to link against libncurses.a. 
 
 
Yes, I know it... (I can use any C library writing my own interface). But that's not what i'm talking... int getch(); int getche(); int kbhit(); Not defined in linux stdio.h and are included in std.c.stdio. That's why i suggest to define only for windows version regards Julio Jiménez
Fuera Chávez
Mar 12 2004
parent =?ISO-8859-1?Q?Julio_Jim=E9nez?= <jujibo inicia.es> writes:
lord.vegeta ica.luz.ve wrote:
 It has been a long time since the last time I programmed something in C for
 windows/dos, but the functions getch(), getche() and kbhit() were always
 declared in a 
 compiler specific conio.h and not in stdio.h. The C standard does
 not include those 
 functions in stdio.h. 
 In curses or ncurses for unix there
 are  equivalent functions, but they do not 
 necessarily have the same names and
 certainly they aren't in stdio.h. 
  
Ok correct, those functions are in conio.h for windows/dos C compiler, but that's not the quiestion. (we are not talking about one or more functions are in stdio.h conio.h bio.h.....) The fact is that we can use wrongly those functions in D under linux and that is wrong, as they are defined in module std.c.stdio for both versions (Linux and Windows). Those functions are not in Linux Standard Library.... there are some equivalent functions in curses library. But really in Linux don't need those functions. Linux is POSIX compliance, a keyboard is a device an i can read and write from devices (any device... not only keyboard) in another standard ways. I think the correct is issolate those functions under the version(windows) {...} or implement equivalent functions for linux version in phobos. In DMD 0.81 i can write this program: -----exaple.d------ import std.c.stdio; void main() { printf("Press a key to continue...\n"); char a = getch(); printf("Ok\n"); } ------------------ and complie ok under linux and windows, but the linker fails in linux version because getch() is not in linux standard library. That's simply wrong regards Julio
Mar 13 2004