Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!wuarchive!psuvax1!psuvm!cunyvm!byuvm!crn From: CRN@BYUVM.BITNET Newsgroups: comp.os.msdos.programmer Subject: Re: This can't be a TurboC bug can it? Message-ID: <90213.121121CRN@BYUVM.BITNET> Date: 1 Aug 90 18:11:21 GMT References: <1990Jul30.050221.29945@caen.engin.umich.edu> <90212.105510CRN@BYUVM.BITNET> <10363@stiatl.UUCP> Organization: Brigham Young University Lines: 64 Subject: Re: This can't be a TurboC bug can it? >CRN@BYUVM.BITNET writes: >>I am having a VERY weird problem in TurboC. My code looks >>something like this: >>typedef struct{ >> . . . >> char *str; >>int type; >>}FIELD; >>int proc(FIELD *fld) >>{ >> . . . >> if(!valid_str(fld->str)) >> return ERROR; >> . . . >>} Tom Wiencko responds: >Turn off register optimization. There must be some code around the >function call which also uses the pointer - and with register optimizaton >turned on the compiler sometimes "forgets" which registers he has used >and which still have valid pointers in them. > >Took me two days of intense debugging to find this, and it was confirme >by Borland tech support. They also said that there is at this time no >fix for the problem. > >I am not sure if Turbo C++ has the same bug - I have not tested it yet >(but I have left the optimization off...). >Tom Thanks Tom, I owe you dinner. That was exactly the problem. Once I turned off register optimization ("-r-" on the command line that invokes tcc, if anyone is interested), the pointers were no longer getting destroyed and the code worked perfectly. Thanks also to everyone else who responded privately to me. And in response to the guy who (mildly) flamed me: I put *alot* of work into debugging that code segment before I placed the post. I had worked through the code many times and could not find any problem with my logic, that's why I speculated in the subject line of the post that I may have found a bug in Turbo C. I'll be more careful next time to make sure my post reflects the work I've done before I place it. By the way, I tested the code with Turbo C++ and the same thing happened, so it looks like it has the same bug. One quick question: Have you noticed a great speed difference between your code that was compiled using register optimization as opposed to your code compiled without such optimization? P.S. Tom, I'm serious about that dinner invitation. If you're ever in Provo (I know there's not a very high probability of that happening but I can't afford to fly you here -- I am just a poor grad student after all), look me up. I'm in the phone book. Thanks again, --Cory R. Newey (crn@byuvm.bitnet)