Strange behaviour of "cin"

Arun Saini , Gurgaon arun@ggn.hcltech.com
Sat Feb 16 15:27:00 GMT 2002


 
> > I have provided the trace that is withing the istream.tcc 
> file of libstdc++
> > and not of my code.
> > I cannot post the code for legal reasons.
> 
> You could try to reduce the problem to a small test case that you can
> post.  If you are unable to do this, it is unlikely that your bug will
> be found and fixed.

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



More information about the Libstdc++ mailing list