home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c100 / 1.ddi / STDANS.ZIP / STDANS.TXT
Encoding:
Text File  |  1988-08-20  |  18.2 KB  |  401 lines

  1.     Standard Answers to Frequently Asked Questions
  2.       New, Improved Turbo C++
  3.  
  4.     Don Corbitt (Not for BI) 74017,3244
  5.  
  6.     Last changed 25 July 1990
  7.  
  8. This file has the goal of answering many of the common questions
  9. seen on BPROGB regarding Borland Turbo C++.  I don't represent
  10. Borland, any opinions are my own.
  11.  
  12. There is a similar file called STDANS.TXT in DL5 of BPROGB.  It 
  13. answers common questions that apply to TC++ and TC (and programming
  14. in general).  The file your are now reading is specific to Turbo C++
  15. version 1.0.
  16.  
  17. Overview
  18. ==============
  19. Enable warnings.
  20. Many programming errors can be diagnosed by the compiler.  If
  21. you enable all warning messages you have a much better chance of
  22. writing programs that work the first time.
  23.  
  24. Formatted messages
  25. When you leave messages regarding problems, please use the
  26. /POST UNFORMATTED option.  Otherwise, CIS (Compuserve Information
  27. Service) will re-format your program into a jumbled mess.
  28.  
  29. RTM - Read The Manual - readme and helpme!.doc
  30. Before spending $$$ on CIS, it is often useful to read the
  31. documentation.  Also, look at the files README and HELPME!.DOC
  32. included with TC.  They list fixes to many common programming
  33. errors.  The TC++ 1.0 manuals have a lot of good information.
  34.  
  35. HELP ME!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  36. ========================================
  37. If you're just getting started, and nothing seems to be working,
  38. see these questions first:
  39.   Q4  - assembly code and 3rd party libraries (also Q24)
  40.   Q9  - editor hangs when copying blocks of text
  41.   Q15 - large model and stack checking
  42.   Q19 - overlays and data-only modules
  43.   Q22 - overlays and exit() with C++ or atexit() functions
  44.   Q23 - mouse driver incompatible
  45.   Q24 - assembly code and 3rd party libraries
  46.   Q31 - TDxxx/TProfxxx don't load
  47.  
  48. TAPCIS
  49. Q1. What is TAPCIS, and how does it help?
  50. A. TAPCIS is a program that calls CIS, checks for new messages,
  51. saves them on disk, and hangs up.  Then it lets you examine the
  52. messages at your own pace, write replies, etc.  TAPCIS then calls
  53. CIS back, and uploads replies you have written.  It saves a lot
  54. on connect charges.  GO TAP for more information.  It is
  55. shareware, and registration is expected if you like it.  Another
  56. program (ATO) is free, but I haven't used it.
  57.  
  58. OS|2/Windows linking
  59. Q2. Can I use TC for OS|2 or Windows?
  60. A. Windows and OS/2 are both 'strategic areas' for Borland. This 
  61. means that eventually BI's main products will work under DOS, 
  62. Windows, and OS|2-PM.  At this time, the outside world doesn't 
  63. know what the timetable is.  It doesn't do any good to ask for 
  64. specific dates, because the people that know aren't allowed to 
  65. say.  "Borland does not pre-announce product releases."
  66.  
  67. Q3. Why is this C++ program illegal?
  68.   void main() {
  69.     int i;
  70.     for (i=0; i<10; i++)
  71.       for (int j=0; j<10; j++)
  72.     ;
  73.     printf("j = %d\n", j);
  74.   }
  75. A. The AT&T C++ 2.0 specification stated that variables can't be
  76.   declared in such a way that the initializer may never execute, but
  77.   they are still in scope.  Turbo C implements this 2.0 rule.  This
  78.   rule was changed back in the AT&T 2.1 spec, and I expect a future
  79.   version from Borland will follow C++ 2.1.
  80.   A simple workaround is to add braces around the inner 'for' loop:
  81.  
  82.   void main() {
  83.     for (int i=0; i<10; i++) {
  84.       for (int j=0; j<10; j++)
  85.         ;
  86.     }
  87.   }
  88.  
  89. Q4. Why does malloc() corrupt memory?
  90.    Why does my program fail in mysterious ways?
  91.    Why does my program die when linked with TLINK 3.0, but
  92.    work with TLINK 2.0?
  93.    (etc.)
  94. A. If you are linking in any assembly code, look for the DOSSEG
  95.    directive.  DOSSEG was defined for a previous version of MSC
  96.    compilers, and is not currently needed.  In fact, it conflicts
  97.    with the segment ordering of Turbo C++.  Previous versions of
  98.    TLINK ignored the DOSSEG record, so they (often) worked.  The
  99.    solution is to remove DOSSEG from your assembly source, and
  100.    reassemble.  If you are linking with third party libraries
  101.    and don't have the source, ask them to send you a new library.
  102.    If they can't/won't, try linking in the integrated environment,
  103.    and find a new library vendor that is easier to work with! :-)
  104.  
  105. Q5. Why does qsort() give a warning/error, when it worked fine under
  106.    TC 2.0.
  107. A. TC++ 1.0 is more strict in ANSI compliance.  It is warning you
  108.    that your program may not work on certain computers.  Two examples
  109.    of correct compare functions are:
  110.  
  111.   /* if sorting an array of integers */
  112.   int fcmp(void const *p1, void const *p2) {
  113.     const int *ip1 = p1;
  114.     const int *ip2 = p2;
  115.     if (*ip1 < *ip2) return -1;
  116.     if (*ip1 > *ip2) return 1;
  117.     return 0;
  118.   }
  119.  
  120.   /* if sorting an array of strings */
  121.   int fcmp(void const *p1, void const *p2) {
  122.     return strcmp(p1, p2);
  123.   }
  124.  
  125. Q6. When I use overlays, I get a linker warning that setjmp and
  126.    longjmp are multiply defined.  Why?
  127. A. OVERLAY.LIB includes its own setjmp and longjmp.  This warning
  128.    is expected, and correct.  You can disable it if you wish.
  129.  
  130. Q7. Why is Turbo Debugger 2.0 so much slower than TD 1.5?
  131. A. For some machines, TD2 seems much slower, but not on others.
  132.    Suggestions for increasing speed are
  133.      1) disable execution history each time you run
  134.      2) update your mouse driver to latest release
  135.      3) disable use of mouse in TD
  136.      4) use MOUSTR.LZH from PCVENB DL 6 to speed up operation of
  137.     recent Microsoft mouse drivers
  138.  
  139. Q8. Can I place third party libraries in VROOM overlays?
  140. A. Yes, if the vendor compiled with the -Y switch, or you have
  141.    source and recompile with -Y.  If your vendor won't do so, 
  142.    tell Borland and they will try to encourage them to fully 
  143.    support VROOM.
  144.  
  145. Q9. When I try to copy a block in the IDE, the system hangs.
  146. A. There is a bug in the editor - if the file ends in Ctrl-Z, the
  147.    last line is not terminated with CRLF, and there are an odd
  148.    number of chars in the last line, this will happen.
  149.    Workarounds are to terminate with CRLF, or remove the Ctrl-Z.
  150.    TC 2.0 inserts Ctrl-Z, while simply saving the file from TC++ 1.0
  151.    will strip them.
  152.  
  153. Q10. I ordered the ProPack upgrade option for $125.  Why didn't I get
  154.    new TASM manuals?
  155. A. Although TC++ 1.0 is _not_ an upgrade from TC 2.0, the Pro-Pack
  156.    part of the package (TD, TASM) is an upgrade.  TASM had very few
  157.    changes, which are documented, so no new manuals were sent out.
  158.    There is a new quick reference guide, which is useful.  If you
  159.    don't have TASM 1.0 manuals, you should have ordered the $145
  160.    special package which is for people that don't have the Propack,
  161.    and need all the manuals.  A few people threw a tantrum when their
  162.    package arrived sans TASM manuals.  Borland agreed to send them
  163.    TASM 2.0 manuals, and make sure any future purchasers know what
  164.    each order contains.  The opinion of most people who received
  165.    new manuals is that they shouldn't have bothered.
  166.  
  167. Q11. I ordered the upgrade through Borland for $xxx, and the next week
  168.    I found the same package for $xxx-10 at the local "Software Is Us"
  169.    store?  Why is Borland ripping off its loyal customers!!!!!
  170. A. There are two parts to this answer...
  171.     1) Take a deep breath, count to ten, exhale slowly.
  172.        Now that you feel more relaxed...
  173.     2) C++ is a new product, so the special deals for past customers
  174.        are not as special.  Each store/distributor is free to charge
  175.        what it wishes for software, including selling at or below
  176.        cost.  Since they buy in huge quantity, they get very
  177.        good prices, and handling/postage is much lower than
  178.        individual sales.  So I recommend checking with your local
  179.        discount house before placing an order direct to Borland.
  180.     PS - Egghead Software had a typo in their advertisements.  
  181.        It looked like they were selling TC++ Pro Pack for $90, 
  182.        when it was really just TC++ 1.0, no TASM/TD/TProf, etc.
  183.  
  184. Q12. What happened to the inportb() and outportb() inline macros
  185.    in dos.h?
  186. A. They accidentally got left out.  You can copy the definitions 
  187.    below into dos.h after the geninterrupt() definition.  BTW,
  188.    there are also definitions for word IO, but they don't work
  189.    correctly in this release of the compiler.
  190.  
  191.   unsigned char    _Cdecl  __inportb__    (int portid);
  192.   #define inportb(portid) __inportb__(portid)/* Byte IN instruction */
  193.  
  194.   void    _Cdecl  __outportb__    (int portid, unsigned char value);
  195.   #define outportb(portid, v) __outportb__(portid,v)/* Byte OUT instruction */
  196.  
  197. Q13. Why do vXprintf() routines expect that the __arglist parameter
  198.    point to the stack?
  199. A. Because programs that follow the rules of STDARG.H always pass
  200.    pointers to their stack arguments.  Many months ago someone from
  201.    Borland asked if that would be a reasonable requirement, and no
  202.    one could think of a reason why not.
  203.    Calling a function expecting a va_list with some other object is
  204.    non-portable, and doesn't work in this release of the compiler.
  205.    Fix your program.
  206.  
  207. Q14. Why does linking with WILDARGS.OBJ cause my program to crash?
  208. A. There appears to be a bug using WILDARGS.OBJ and large model
  209.    programs.  Found by Hyman Rosen 74716,3415.  He announced a
  210.    fixed WILDARGS.OBJ has been uploaded to DL4, it may have been
  211.    moved to DL3 by now.  There have also been reports of another bug
  212.    in tiny model, which should soon be fixed.
  213.  
  214. Q15. Why does my large model program not work?
  215. A. If stack checking is enabled, turn it off.  Stack check in
  216.    large model is said to not work properly.
  217.  
  218. Q16. What is a good book for learning C++ programming?
  219. A. C++ Primer, Stanley B. Lippman, ISBN 0-201-16487-6.  For a
  220.    reference book, see Annotated C++ Reference Manual, Ellis &
  221.    Stroustrup, ISBM 0-201-51459-1.
  222.  
  223. Q17. Why does the linker complain about missing functions when
  224.    I use C++ streams?
  225. A. If you have selected Unsigned Chars:ON, change back to off,
  226.    or edit the <iostream.h> file on lines 577, 593, 597 to be
  227.    (const signed char *) in place of (const char *).
  228.  
  229. Q18. Where are the programs TCCNVT.EXE and PRJ2MAKE.EXE?
  230. A. These utilities were not completed in time for shipment, and
  231.    should have been removed from the manuals.  There is no
  232.    information on future plans regarding them.
  233.  
  234. Q19. Why does my program crash when I link with overlays, but work
  235.    ok without them?
  236. A. Are you overlaying any modules that are data-only?  Create a 
  237.    detailed .MAP file, and see if any of the code segments being
  238.    overlayed are 0 bytes long.  If so, don't overlay that module.
  239.    
  240. Q20. Why doesn't the preprocessor 'stringize' my macro?  This works
  241.    OK in TC 2.0:
  242.    #define TEMP 5
  243.    #define STR(x) #x
  244.      printf("TEMP is %s\n", STR(TEMP));
  245. A. ANSI has defined how the preprocessor converts macros.  This will
  246.    work:
  247.    #define STR(x) STR1(x)
  248.    #define STR1(x) #x
  249.    
  250. Q21. Why doesn't MK_FP work the same way?
  251. A. For most arguments to the MK_FP macro you will get the same results.
  252.    However, if you are passing a long value, you may get something 
  253.    unexpected.  You should pass two integers as parameters.
  254.    
  255. Q22. I'm using overlays and C++.  Why does my system crash when exit() is
  256.    called?
  257. A. There is a bug in c0.asm.  Either don't call exit() when using overlays
  258.    and C++, or make this change to c0.asm, and run BUILDC0.BAT.
  259.    To change your c0.asm, follow these steps:
  260.      1) unzip the file STARTUP.ZIP in /turboc/examples
  261.      2) edit C0.ASM, moving these lines
  262.                 mov     byte ptr cs:JA_JB,72h
  263.                 mov     byte ptr cs:StartExit+1,0
  264.         to before the 
  265.                 call    _main
  266.      3) run the BUILD-C0 batch file
  267.      4) link with the new C0x.OBJ file
  268.  
  269. Q23. Nothing seems to be working.  I get crashes when compiling, or
  270.    running program that seemed to work before.  What's wrong?
  271. A. A common cause of mysterious crashes is using an old mouse driver.
  272.    TC (and TD, TProf, etc) use some mouse driver features that old
  273.    mice don't have.  This allows them to share the mouse between the
  274.    program being tested, and TC.  An old driver can cause various
  275.    problems.  Note that your mouse may work with other programs,
  276.    and still not support the functions TC/TD require.
  277.      You can get new drivers at these locations:
  278.      Mouse Systems Version 6.1  (415) 683-0617
  279.      Logitech      Version 4.1  ????
  280.      Microsoft     Version      ????
  281.      Genius        Version      ????
  282.  
  283. Q24. Why am I getting memory overwrites at run time?
  284. A. If you link any code that defines CONST segments this will 
  285.    confuse TLINK.  Either you need to add CONST segments to
  286.    the proper place in C0.ASM, or remove the CONST segments
  287.    from your code.
  288.  
  289. Q25. How can I tell if I'm linking in improper assembly routines?
  290. A. Create a detailed map file.  The segment order should in
  291.    general be as follows:
  292.    
  293.  Start  Stop   Length Name               Class  Comments 
  294.  00000H 00433H 00434H _TEXT              CODE   One or more CODE segments
  295.  01AC5H 01D13H 0024FH TZSET_TEXT         CODE
  296.  01D20H 022C2H 005A3H _DATA              DATA   One or more DATA segments
  297.  022CEH 022D9H 0000CH _SCNSEG            DATA
  298.  022DAH 02367H 0008EH _BSS               BSS    The _BSS segment
  299.  02368H 02368H 00000H _BSSEND            STACK  Then _BSSEND with class STACK
  300.  02370H 023EFH 00080H _STACK             STACK  Then finally STACK
  301.  
  302. Q26. TLink crashes when linking in my own ASM file?
  303. A. If you enabled debugging symbols (/zi), and have multiple symbols
  304.    with the same name (@@1:, etc) this may confuse TLINK.  Change
  305.    the symbol names, or use the (/zd) option.
  306.    
  307. Q27. Why are my CIS messages being erased and no one answers them?
  308. A. Have you considered changing deodorant?  Just joking - it's nothing
  309.    personal.  There are (at least) four possible explanations:
  310.      a) You are using Compuserve Navigator.  I've heard that it can be
  311.     difficult to re-read messages you have sent.
  312.      b) People saw your message, answered it, but you didn't check back
  313.     quickly enough.  Compuserve limits the number of messages that
  314.     can exist.  Each time a new message is posted, an old one gets
  315.     deleted.  Scroll rate can be 24 hours when a new product is just
  316.     released, or several days when things are quiet.  Check back
  317.     in 24 hours, and again 48 hours after leaving your question.
  318.      c) People saw your message, but didn't know the answer to the
  319.     question.  The "For BI" volunteers answer questions they know the
  320.         answer to, but pass on some questions to Borland support.  After
  321.         several days of no response, repost asking if your message was
  322.         seen, and if anyone has even a slight hint what the answer was.
  323.      d) Your message contained a personal attack on a member of the forum.
  324.         These messages are made private, and the culprit is admonished to
  325.         use better mannors.
  326.    Remember that most of the answers posted here are by volunteers, trying
  327.    to help.  If you slip through the cracks, it is better to assume overwork 
  328.    and confusion than malice and incompetence.
  329.  
  330. Q28. Why can't I use TD386 with (QEMM, 386Max, CEMM, other 386 control
  331.    programs)?
  332. A. To do its thing, TD386 needs to be in charge of the 386.  These EMS
  333.    emulators also need to have the same control.  There is a standard for
  334.    virtual 8086 emulators, VCPI.  Unfortunately, this standard doesn't
  335.    contain calls for supporting the needs of TD386.  Yet another control
  336.    standard is being released DPMI (Dos Protect Mode Interface), which
  337.    Borland is supporting.  Hopefully a future version of TD386 and QEMM
  338.    will support DPMI.  You may be able to use TD286 if your memory 
  339.    manager is VCPI compatible.
  340.  
  341. Q29. Why doesn't __emit__(&var) work?
  342. A. Because it is broken in TC++ 1.0.  It doesn't place the address/
  343.    offset of the variable.  Sorry.
  344.  
  345. Q30. I'm using C++, and trying to link in some C or ASM code.  Why can't
  346.    the linker find some symbols?
  347. A. C++ tries to prevent programmer errors by encoding the arguments of
  348.    a function in the function name.  You can get around this by declaring
  349.    your extern functions as "C" as follows:
  350.      extern "C" int foo(int __arg1, int __arg2);
  351.    If you have a section of declarations, you can bracket them with
  352.      extern "C" {
  353.        int foo(int __arg1, int __arg2);
  354.        float bar(float __arg);
  355.      }
  356.    See the standard header files for examples of this method.
  357.  
  358. Q31. Why don't TD386 or TProf work on my system?
  359. A. If your environment variables take up more than 512 bytes, some of
  360.    the TDxxx/TProfxxx programs won't work.  You can remove environment
  361.    variables temorarily while running these programs.
  362.  
  363. Q32. Why is a variable changed after longjmp() is called?
  364. A. It appears that setjmp()/longjmp() don't properly restore the
  365.    DI register.  A workaround is to use _DI in the routine that
  366.    calls setjmp(), so the compiler doesn't put anything in that
  367.    register.
  368.  
  369. Q33. Why does my project file keep getting larger?
  370. A. There is a problem with TC++ saving extra information in the
  371.    project file each time the file is saved.  This can be worked
  372.    around by setting Options/Environment/Preferences/Auto Save Project
  373.    to OFF, and only saving your project file when you make changes.
  374.    Another workaround may be to clear the contents of the clipboard.
  375.  
  376. Q34. When passing a structure or structure pointer, why do I need to
  377.    declare it twice?  Shouldn't the structure definition in the function
  378.    prototype also declare the structure?
  379. A. No, a structure declared in a function prototype goes out of scope at
  380.    the end of the prototype.  This is for ANSI compatibility.
  381.    Example:
  382.      /* struct y; /* uncomment this to make it work */
  383.      void foo(struct y *yp);
  384.      struct y {int a;};
  385.      int foo(struct y *yp) { return y->a; }
  386.    The first 'struct y' goes out of scope at the end of the prototype.
  387.    You should uncomment the previous tag (or move the struct definition
  388.    before the function prototype) to fix your bug.
  389.  
  390. Q35. Is the switch for snow checking broken/backwards in TCINST?
  391. A. Yes, to disable snow checking, set it to enable, and vice versa.
  392.  
  393.  
  394. If any of this information is outdated, or not correct, or if you
  395. have any suggestions for other items to cover, please let me know.
  396. I will try to update this file (and STDANS.TXT on DL5) several times
  397. a year, but only if I get the feeling it is useful to others.
  398.  
  399.     Don Corbitt  74017,3244
  400.     Sunnyvale, California
  401.