Topic: putback trap?


Author: Won Kim <wokim@lehman.COM>
Date: 1999/03/16
Raw View
Hello,

This is a weird snip of code that I have been given to work on.  I am
trying to convert this code to use "TCHAR" string buffer rather then
streams.  I am trying to understand what will happen in this code that
uses streams inorder to convert it to a string buffer.  Can anyone
explain what is happening and what this will do?

This is one case statement on a large switch.  It seems that the
original programmer wrote a "TODO" note stating that "more than one
putback between gets is non-portable".  Isn't it true that not all the
i.get() in the first "if" may not be executed or undefined?

//    istream& i
//    int k, k1, k2, k3, tmp, ind;
//    int retval = 0;

    case DT_WDAY:
 if( (tmp= GetWDay( 0,   (k1= i.get()), ind= 0)) > 0 &&
     (tmp= GetWDay( tmp, (k2= i.get()), ind= 1)) > 0 &&
     (tmp= GetWDay( tmp, (k3= i.get()), ind= 2)) > 0)
     break;
 retval = ind;
 switch( ind)
 {
 // TODO: more than one putback between gets is non-portable;
 // this should be rewritten when time allows
 case 2: if (k3 != EOF) i.putback(k3);
 case 1: if (k2 != EOF) i.putback(k2);
 case 0: if (k1 != EOF) i.putback(k1);
 } break;

Any help would really be appreciated.

Won Kim



[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]