This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: Strange behaviour of "cin"


> >Ok. I finally traced the problem to the ctype header. I 
> wrote a small test
> >program. It consists of a shared library and an executable 
> that is linked to
> >that shared library.
> >
> >The contents of the shared library are :
> >
> >/* file : mylib.cpp */
> >#include <ctype.h>
> >
> >int f(unsigned char c)
> >{
> >   if (isspace(c));
> >
> >   return 0;
> >}
> >
> >
> >The executable is :
> >
> >/* file : mytest.cpp */
> >#include <iostream>
> >
> >int main()
> >{
> >   int num1, num2;
> >
> >   std::cout << "Enter number 1 ->> ";
> >   std::cin >> num1;
> >
> >   std::cout << std::endl << "Enter number 2 ->> ";
> >   std::cin >> num2;
> >
> >   std::cout << std::endl << num1 << " + " << num2 << " = " 
> << num1 + num2;
> >
> >   return 0;
> >}
> >
> >I do the following :
> >
> >$ g++ -g3 -fPIC -c mylib.cpp
> >$ g++ -G mylib.o -o libmylib.so
> >$ g++ -g3 -fPIC -c mytest.cpp
> >$ g++ mytest.o -L. -lmylib -o mytest
> >
> >$ ./mytest
> >Enter number 1 ->> 12
> >
> >Enter number 2 ->>
> >-2147398527 + -2147110048 = 4587211535$
> >
> >The crux is that the "cin" fails to accept a value. It waits 
> for the user to
> >input a value first time but subsequently it doesn't even stop.
> >Now in the shared library (mylib.cpp) above, if I change the 
> header from
> >"ctype.h" to "cctype", the program executes correctly.
> >
> >Any ideas???
> >
> >Arun Saini
> 
> Well, <cctype> is the Right header for C++.
> However, I tried it, and it works for me, both with <ctype.h> 
> and <cctype>. 
> In either case, it goes like
> 
> $ g++3 -g3 -fPIC -c mylib.cc
> $ g++3 -shared mylib.o -o libmylib.so
> $ g++3 -g3 -fPIC -c mytest.cc
> $ g++3 mytest.o -L. -lmylib -o mytest
> $ ./mytest
> Enter number 1 ->> 12
> 
> Enter number 2 ->> 30
> 
> 12 + 30 = 42
> 
> 
> /*
> RedHat Linux 7.2
> GCC 3.0.2
> Configured with: ../configure --prefix=/usr --mandir=/usr/share/man 
> --infodir=/usr/share/info --enable-shared --enable-threads=posix 
> --disable-checking --host=i386-redhat-linux
> Thread model: posix
> gcc version 3.0.2 20010905 (Red Hat Linux 7.1 3.0.1-3)
> */
> 
> fwyzard
> 

I am sorry I should have mentioned it again, I did that in my initial mail.
I am using gcc 3.0.3 on SCO 5.0.5.
Is this a peculiar behaviour on SCO or is gcc not able to *fix* this header
correctly. I suspect the reason to be
the inline definitions, and there corresponding macro definitions, for
various type identification functions present
in the <ctype.h> header. These are over-ridden if we use <cctype>.

/*
Reading specs from /usr/local/lib/gcc-lib/i386-pc-sco3.2v5.0.5/3.0.3/specs
Configured with: ../gcc-3.0.3/configure --enable-shared --disable-multilib
--enable-languages=c,c++ --disable-threads
Thread model: single
gcc version 3.0.3
*/


 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]