This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


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

a bug?


Hi, 

I'm using GCC 2.95.2 on debian potato 
on a Pentium II machine.  libc6 2.1.2-11

The following short program illustrates what appears to be
a potential problem with GCC or libc6, the comment includes details.
any more questions, E-mail me at djdibble@cats.ucsc.edu.  I have no 
idea on whether or not this really is a bug; or if it is, how 
to fix it, I know much less than you do...

Thanks,
Josh Dibble; lowly computer tinkerer

/* this illustrates a difference between different versions of the GCC 
compiler
 * or possible bug in it's working.
 * scanf returns -1 (float scan) for a +  or - character and 
 * fails to scan (char scan) on GCC > 2.9 and
 * returns +1 (char scan) for same and succesfully scans character on GCC 
~ 2.7
 * the latter behavior was required for an assignment I was working on
 * in a computer science class and was considered the proper behavior
 * in the following example. 
 *
 * i.e. compile this, type in any character and number except + and - and
 * the program works fine, then type in + and - and see what happens
 * (compliled w/ GCC 2.95)
 */

#include <stdio.h>


int main(void){

  int intReturn;
  int charReturn;
  float floating;
  char character;
  
  intReturn = scanf("%f", &floating);
  if(intReturn == 0){
    charReturn = scanf("%c", &character);
  }
  printf("\nfloating point scanf return value:%i", intReturn);
  printf("\nfloating point value:%f", floating);
  printf("\ncharacter scanf return value:%i", charReturn);
  printf("\ncharacter value:%c\n", character);
return 0;
}


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