home *** CD-ROM | disk | FTP | other *** search
- Standard Answers to Frequently Asked Questions
- New, Improved Turbo C++
-
- Don Corbitt (Not for BI) 74017,3244
-
- Last changed 25 July 1990
-
- This file has the goal of answering many of the common questions
- seen on BPROGB regarding Borland Turbo C++. I don't represent
- Borland, any opinions are my own.
-
- There is a similar file called STDANS.TXT in DL5 of BPROGB. It
- answers common questions that apply to TC++ and TC (and programming
- in general). The file your are now reading is specific to Turbo C++
- version 1.0.
-
- Overview
- ==============
- Enable warnings.
- Many programming errors can be diagnosed by the compiler. If
- you enable all warning messages you have a much better chance of
- writing programs that work the first time.
-
- Formatted messages
- When you leave messages regarding problems, please use the
- /POST UNFORMATTED option. Otherwise, CIS (Compuserve Information
- Service) will re-format your program into a jumbled mess.
-
- RTM - Read The Manual - readme and helpme!.doc
- Before spending $$$ on CIS, it is often useful to read the
- documentation. Also, look at the files README and HELPME!.DOC
- included with TC. They list fixes to many common programming
- errors. The TC++ 1.0 manuals have a lot of good information.
-
- HELP ME!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- ========================================
- If you're just getting started, and nothing seems to be working,
- see these questions first:
- Q4 - assembly code and 3rd party libraries (also Q24)
- Q9 - editor hangs when copying blocks of text
- Q15 - large model and stack checking
- Q19 - overlays and data-only modules
- Q22 - overlays and exit() with C++ or atexit() functions
- Q23 - mouse driver incompatible
- Q24 - assembly code and 3rd party libraries
- Q31 - TDxxx/TProfxxx don't load
-
- TAPCIS
- Q1. What is TAPCIS, and how does it help?
- A. TAPCIS is a program that calls CIS, checks for new messages,
- saves them on disk, and hangs up. Then it lets you examine the
- messages at your own pace, write replies, etc. TAPCIS then calls
- CIS back, and uploads replies you have written. It saves a lot
- on connect charges. GO TAP for more information. It is
- shareware, and registration is expected if you like it. Another
- program (ATO) is free, but I haven't used it.
-
- OS|2/Windows linking
- Q2. Can I use TC for OS|2 or Windows?
- A. Windows and OS/2 are both 'strategic areas' for Borland. This
- means that eventually BI's main products will work under DOS,
- Windows, and OS|2-PM. At this time, the outside world doesn't
- know what the timetable is. It doesn't do any good to ask for
- specific dates, because the people that know aren't allowed to
- say. "Borland does not pre-announce product releases."
-
- Q3. Why is this C++ program illegal?
- void main() {
- int i;
- for (i=0; i<10; i++)
- for (int j=0; j<10; j++)
- ;
- printf("j = %d\n", j);
- }
- A. The AT&T C++ 2.0 specification stated that variables can't be
- declared in such a way that the initializer may never execute, but
- they are still in scope. Turbo C implements this 2.0 rule. This
- rule was changed back in the AT&T 2.1 spec, and I expect a future
- version from Borland will follow C++ 2.1.
- A simple workaround is to add braces around the inner 'for' loop:
-
- void main() {
- for (int i=0; i<10; i++) {
- for (int j=0; j<10; j++)
- ;
- }
- }
-
- Q4. Why does malloc() corrupt memory?
- Why does my program fail in mysterious ways?
- Why does my program die when linked with TLINK 3.0, but
- work with TLINK 2.0?
- (etc.)
- A. If you are linking in any assembly code, look for the DOSSEG
- directive. DOSSEG was defined for a previous version of MSC
- compilers, and is not currently needed. In fact, it conflicts
- with the segment ordering of Turbo C++. Previous versions of
- TLINK ignored the DOSSEG record, so they (often) worked. The
- solution is to remove DOSSEG from your assembly source, and
- reassemble. If you are linking with third party libraries
- and don't have the source, ask them to send you a new library.
- If they can't/won't, try linking in the integrated environment,
- and find a new library vendor that is easier to work with! :-)
-
- Q5. Why does qsort() give a warning/error, when it worked fine under
- TC 2.0.
- A. TC++ 1.0 is more strict in ANSI compliance. It is warning you
- that your program may not work on certain computers. Two examples
- of correct compare functions are:
-
- /* if sorting an array of integers */
- int fcmp(void const *p1, void const *p2) {
- const int *ip1 = p1;
- const int *ip2 = p2;
- if (*ip1 < *ip2) return -1;
- if (*ip1 > *ip2) return 1;
- return 0;
- }
-
- /* if sorting an array of strings */
- int fcmp(void const *p1, void const *p2) {
- return strcmp(p1, p2);
- }
-
- Q6. When I use overlays, I get a linker warning that setjmp and
- longjmp are multiply defined. Why?
- A. OVERLAY.LIB includes its own setjmp and longjmp. This warning
- is expected, and correct. You can disable it if you wish.
-
- Q7. Why is Turbo Debugger 2.0 so much slower than TD 1.5?
- A. For some machines, TD2 seems much slower, but not on others.
- Suggestions for increasing speed are
- 1) disable execution history each time you run
- 2) update your mouse driver to latest release
- 3) disable use of mouse in TD
- 4) use MOUSTR.LZH from PCVENB DL 6 to speed up operation of
- recent Microsoft mouse drivers
-
- Q8. Can I place third party libraries in VROOM overlays?
- A. Yes, if the vendor compiled with the -Y switch, or you have
- source and recompile with -Y. If your vendor won't do so,
- tell Borland and they will try to encourage them to fully
- support VROOM.
-
- Q9. When I try to copy a block in the IDE, the system hangs.
- A. There is a bug in the editor - if the file ends in Ctrl-Z, the
- last line is not terminated with CRLF, and there are an odd
- number of chars in the last line, this will happen.
- Workarounds are to terminate with CRLF, or remove the Ctrl-Z.
- TC 2.0 inserts Ctrl-Z, while simply saving the file from TC++ 1.0
- will strip them.
-
- Q10. I ordered the ProPack upgrade option for $125. Why didn't I get
- new TASM manuals?
- A. Although TC++ 1.0 is _not_ an upgrade from TC 2.0, the Pro-Pack
- part of the package (TD, TASM) is an upgrade. TASM had very few
- changes, which are documented, so no new manuals were sent out.
- There is a new quick reference guide, which is useful. If you
- don't have TASM 1.0 manuals, you should have ordered the $145
- special package which is for people that don't have the Propack,
- and need all the manuals. A few people threw a tantrum when their
- package arrived sans TASM manuals. Borland agreed to send them
- TASM 2.0 manuals, and make sure any future purchasers know what
- each order contains. The opinion of most people who received
- new manuals is that they shouldn't have bothered.
-
- Q11. I ordered the upgrade through Borland for $xxx, and the next week
- I found the same package for $xxx-10 at the local "Software Is Us"
- store? Why is Borland ripping off its loyal customers!!!!!
- A. There are two parts to this answer...
- 1) Take a deep breath, count to ten, exhale slowly.
- Now that you feel more relaxed...
- 2) C++ is a new product, so the special deals for past customers
- are not as special. Each store/distributor is free to charge
- what it wishes for software, including selling at or below
- cost. Since they buy in huge quantity, they get very
- good prices, and handling/postage is much lower than
- individual sales. So I recommend checking with your local
- discount house before placing an order direct to Borland.
- PS - Egghead Software had a typo in their advertisements.
- It looked like they were selling TC++ Pro Pack for $90,
- when it was really just TC++ 1.0, no TASM/TD/TProf, etc.
-
- Q12. What happened to the inportb() and outportb() inline macros
- in dos.h?
- A. They accidentally got left out. You can copy the definitions
- below into dos.h after the geninterrupt() definition. BTW,
- there are also definitions for word IO, but they don't work
- correctly in this release of the compiler.
-
- unsigned char _Cdecl __inportb__ (int portid);
- #define inportb(portid) __inportb__(portid)/* Byte IN instruction */
-
- void _Cdecl __outportb__ (int portid, unsigned char value);
- #define outportb(portid, v) __outportb__(portid,v)/* Byte OUT instruction */
-
- Q13. Why do vXprintf() routines expect that the __arglist parameter
- point to the stack?
- A. Because programs that follow the rules of STDARG.H always pass
- pointers to their stack arguments. Many months ago someone from
- Borland asked if that would be a reasonable requirement, and no
- one could think of a reason why not.
- Calling a function expecting a va_list with some other object is
- non-portable, and doesn't work in this release of the compiler.
- Fix your program.
-
- Q14. Why does linking with WILDARGS.OBJ cause my program to crash?
- A. There appears to be a bug using WILDARGS.OBJ and large model
- programs. Found by Hyman Rosen 74716,3415. He announced a
- fixed WILDARGS.OBJ has been uploaded to DL4, it may have been
- moved to DL3 by now. There have also been reports of another bug
- in tiny model, which should soon be fixed.
-
- Q15. Why does my large model program not work?
- A. If stack checking is enabled, turn it off. Stack check in
- large model is said to not work properly.
-
- Q16. What is a good book for learning C++ programming?
- A. C++ Primer, Stanley B. Lippman, ISBN 0-201-16487-6. For a
- reference book, see Annotated C++ Reference Manual, Ellis &
- Stroustrup, ISBM 0-201-51459-1.
-
- Q17. Why does the linker complain about missing functions when
- I use C++ streams?
- A. If you have selected Unsigned Chars:ON, change back to off,
- or edit the <iostream.h> file on lines 577, 593, 597 to be
- (const signed char *) in place of (const char *).
-
- Q18. Where are the programs TCCNVT.EXE and PRJ2MAKE.EXE?
- A. These utilities were not completed in time for shipment, and
- should have been removed from the manuals. There is no
- information on future plans regarding them.
-
- Q19. Why does my program crash when I link with overlays, but work
- ok without them?
- A. Are you overlaying any modules that are data-only? Create a
- detailed .MAP file, and see if any of the code segments being
- overlayed are 0 bytes long. If so, don't overlay that module.
-
- Q20. Why doesn't the preprocessor 'stringize' my macro? This works
- OK in TC 2.0:
- #define TEMP 5
- #define STR(x) #x
- printf("TEMP is %s\n", STR(TEMP));
- A. ANSI has defined how the preprocessor converts macros. This will
- work:
- #define STR(x) STR1(x)
- #define STR1(x) #x
-
- Q21. Why doesn't MK_FP work the same way?
- A. For most arguments to the MK_FP macro you will get the same results.
- However, if you are passing a long value, you may get something
- unexpected. You should pass two integers as parameters.
-
- Q22. I'm using overlays and C++. Why does my system crash when exit() is
- called?
- A. There is a bug in c0.asm. Either don't call exit() when using overlays
- and C++, or make this change to c0.asm, and run BUILDC0.BAT.
- To change your c0.asm, follow these steps:
- 1) unzip the file STARTUP.ZIP in /turboc/examples
- 2) edit C0.ASM, moving these lines
- mov byte ptr cs:JA_JB,72h
- mov byte ptr cs:StartExit+1,0
- to before the
- call _main
- 3) run the BUILD-C0 batch file
- 4) link with the new C0x.OBJ file
-
- Q23. Nothing seems to be working. I get crashes when compiling, or
- running program that seemed to work before. What's wrong?
- A. A common cause of mysterious crashes is using an old mouse driver.
- TC (and TD, TProf, etc) use some mouse driver features that old
- mice don't have. This allows them to share the mouse between the
- program being tested, and TC. An old driver can cause various
- problems. Note that your mouse may work with other programs,
- and still not support the functions TC/TD require.
- You can get new drivers at these locations:
- Mouse Systems Version 6.1 (415) 683-0617
- Logitech Version 4.1 ????
- Microsoft Version ????
- Genius Version ????
-
- Q24. Why am I getting memory overwrites at run time?
- A. If you link any code that defines CONST segments this will
- confuse TLINK. Either you need to add CONST segments to
- the proper place in C0.ASM, or remove the CONST segments
- from your code.
-
- Q25. How can I tell if I'm linking in improper assembly routines?
- A. Create a detailed map file. The segment order should in
- general be as follows:
-
- Start Stop Length Name Class Comments
- 00000H 00433H 00434H _TEXT CODE One or more CODE segments
- 01AC5H 01D13H 0024FH TZSET_TEXT CODE
- 01D20H 022C2H 005A3H _DATA DATA One or more DATA segments
- 022CEH 022D9H 0000CH _SCNSEG DATA
- 022DAH 02367H 0008EH _BSS BSS The _BSS segment
- 02368H 02368H 00000H _BSSEND STACK Then _BSSEND with class STACK
- 02370H 023EFH 00080H _STACK STACK Then finally STACK
-
- Q26. TLink crashes when linking in my own ASM file?
- A. If you enabled debugging symbols (/zi), and have multiple symbols
- with the same name (@@1:, etc) this may confuse TLINK. Change
- the symbol names, or use the (/zd) option.
-
- Q27. Why are my CIS messages being erased and no one answers them?
- A. Have you considered changing deodorant? Just joking - it's nothing
- personal. There are (at least) four possible explanations:
- a) You are using Compuserve Navigator. I've heard that it can be
- difficult to re-read messages you have sent.
- b) People saw your message, answered it, but you didn't check back
- quickly enough. Compuserve limits the number of messages that
- can exist. Each time a new message is posted, an old one gets
- deleted. Scroll rate can be 24 hours when a new product is just
- released, or several days when things are quiet. Check back
- in 24 hours, and again 48 hours after leaving your question.
- c) People saw your message, but didn't know the answer to the
- question. The "For BI" volunteers answer questions they know the
- answer to, but pass on some questions to Borland support. After
- several days of no response, repost asking if your message was
- seen, and if anyone has even a slight hint what the answer was.
- d) Your message contained a personal attack on a member of the forum.
- These messages are made private, and the culprit is admonished to
- use better mannors.
- Remember that most of the answers posted here are by volunteers, trying
- to help. If you slip through the cracks, it is better to assume overwork
- and confusion than malice and incompetence.
-
- Q28. Why can't I use TD386 with (QEMM, 386Max, CEMM, other 386 control
- programs)?
- A. To do its thing, TD386 needs to be in charge of the 386. These EMS
- emulators also need to have the same control. There is a standard for
- virtual 8086 emulators, VCPI. Unfortunately, this standard doesn't
- contain calls for supporting the needs of TD386. Yet another control
- standard is being released DPMI (Dos Protect Mode Interface), which
- Borland is supporting. Hopefully a future version of TD386 and QEMM
- will support DPMI. You may be able to use TD286 if your memory
- manager is VCPI compatible.
-
- Q29. Why doesn't __emit__(&var) work?
- A. Because it is broken in TC++ 1.0. It doesn't place the address/
- offset of the variable. Sorry.
-
- Q30. I'm using C++, and trying to link in some C or ASM code. Why can't
- the linker find some symbols?
- A. C++ tries to prevent programmer errors by encoding the arguments of
- a function in the function name. You can get around this by declaring
- your extern functions as "C" as follows:
- extern "C" int foo(int __arg1, int __arg2);
- If you have a section of declarations, you can bracket them with
- extern "C" {
- int foo(int __arg1, int __arg2);
- float bar(float __arg);
- }
- See the standard header files for examples of this method.
-
- Q31. Why don't TD386 or TProf work on my system?
- A. If your environment variables take up more than 512 bytes, some of
- the TDxxx/TProfxxx programs won't work. You can remove environment
- variables temorarily while running these programs.
-
- Q32. Why is a variable changed after longjmp() is called?
- A. It appears that setjmp()/longjmp() don't properly restore the
- DI register. A workaround is to use _DI in the routine that
- calls setjmp(), so the compiler doesn't put anything in that
- register.
-
- Q33. Why does my project file keep getting larger?
- A. There is a problem with TC++ saving extra information in the
- project file each time the file is saved. This can be worked
- around by setting Options/Environment/Preferences/Auto Save Project
- to OFF, and only saving your project file when you make changes.
- Another workaround may be to clear the contents of the clipboard.
-
- Q34. When passing a structure or structure pointer, why do I need to
- declare it twice? Shouldn't the structure definition in the function
- prototype also declare the structure?
- A. No, a structure declared in a function prototype goes out of scope at
- the end of the prototype. This is for ANSI compatibility.
- Example:
- /* struct y; /* uncomment this to make it work */
- void foo(struct y *yp);
- struct y {int a;};
- int foo(struct y *yp) { return y->a; }
- The first 'struct y' goes out of scope at the end of the prototype.
- You should uncomment the previous tag (or move the struct definition
- before the function prototype) to fix your bug.
-
- Q35. Is the switch for snow checking broken/backwards in TCINST?
- A. Yes, to disable snow checking, set it to enable, and vice versa.
-
-
- If any of this information is outdated, or not correct, or if you
- have any suggestions for other items to cover, please let me know.
- I will try to update this file (and STDANS.TXT on DL5) several times
- a year, but only if I get the feeling it is useful to others.
-
- Don Corbitt 74017,3244
- Sunnyvale, California
-