home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_122 / 6.ddi / DOC.ZIP / HELPME!.DOC < prev    next >
Encoding:
Text File  |  1992-06-10  |  57.1 KB  |  1,280 lines

  1.               Borland C++: ANSWERS TO COMMON QUESTIONS
  2.  
  3.  
  4.  G e t t i n g     S t a r t e d
  5.  ----------------------------------------------------------------------
  6.  Q. How do I install Borland C++?
  7.  A. Run the INSTALL program from DISK 1. To start the installation, change
  8.     your current drive to the one that has the install program on it and
  9.     type INSTALL. You will be given instructions in a box at the bottom of
  10.     the screen for each prompt. For example, if you will be installing from
  11.     drive A:, type:
  12.  
  13.        A:
  14.        INSTALL
  15.  
  16.     At this point, the INSTALL program will appear with menu selections
  17.     and descriptions to guide you through the installation process.
  18.  
  19.  Q. How do I run Borland C++?
  20.  A. After you have installed Borland C++, be sure to add the path to
  21.     the 'BIN' subdirectory of your BC++ installation (e.g., C:\BORLANDC\BIN)
  22.     to your DOS path. Now you can type "BC" at the DOS prompt and from any
  23.     directory and you're ready to go.
  24.  
  25.  Q. What is a configuration file?
  26.  A. A configuration file tells Borland C++ what options to default to
  27.     and where to look for its library and header files. BC.EXE and
  28.     BCW.EXE both look for a configuration file named TCCONFIG.TC, and
  29.     BCC.EXE looks for a file named TURBOC.CFG.
  30.  
  31.  Q. How do I create a configuration file?
  32.  A. When you run the INSTALL program it creates a configuration
  33.     file named TURBOC.CFG for BCC.EXE. This file is just an
  34.     ASCII file, which you can change with any text editor. It
  35.     contains the path information for the library and header
  36.     files for BCC.EXE to use. The INSTALL program does not
  37.     create a TCCONFIG.TC file for BC.EXE and BCW.EXE because it
  38.     installs the directory information directly into BC.EXE. You
  39.     can create a configuration file for the IDEs by running BC.EXE,
  40.     setting your options however you want to set them, and typing
  41.     Alt-O/S.
  42.  
  43.  C o m m o n   C + +   Q u e s t i o n s
  44.  ----------------------------------------------------------
  45.  
  46.  Q. When linking C or Assembly language modules with C++ modules I get
  47.     undefined symbol errors at link time.  It appears that none of the C
  48.     or Assembly public symbols can be found.
  49.  A. C++ is a strongly typed language.  In order to support the language
  50.     to its fullest, Borland C++ must attach information to the symbols
  51.     generated for function names and variables.  When this is done, the
  52.     symbol will no longer match the standard C style function name.  In
  53.     order to link correctly, the compiler must be notified that the symbol
  54.     is declared in an external module without type information tacked on
  55.     to the symbol.  This is done by prototyping the function as type
  56.     extern "C".   Here is a quick example:
  57.        extern "C" int normal_c_func( float, int, char );  // name not altered
  58.        void cplusplus_function( int );  // name altered
  59.     See related comments under Linker Errors and in the Paradox Engine
  60.     question in this section. There is also more on extern "C" in the
  61.     Borland C++ Programmer's Guide, Chapter 1.
  62.  
  63.  Q. Classes with static data members are getting linker errors ("undefined").
  64.  A. This code is built into Turbo C++ 1.0 but not in Borland C++ 2.0, 3.0,
  65.     or 3.1. In the 1.0 compiler, static members without definitions were given
  66.     a default value of 0.  This default definition will no longer be made in
  67.     the compiler.  The programmer must now give an explicit definition for each
  68.     static member.  Here is a quick example:
  69.        class A
  70.        {
  71.       static int i;
  72.        };
  73.     A linker error saying that A::i is not defined will result unless the
  74.     source also contains a line such as:
  75.        int A::i = 1; //i needs to defined but not necessarily initialized
  76.  
  77.     In the case of a template class, you need to similarly define static
  78.     data outside the class definition, and also include the actual type
  79.     information for any type you plan to instantiate the template class
  80.     with. For example:
  81.        template <class T>
  82.        class A
  83.        {
  84.           static int i;
  85.        };
  86.        A<int>::i;  //provide definition for an integer type
  87.        A<Myclass>::i; //provide definition for a user-defined type
  88.  
  89.  Q. What potential problems can arise from typecasting a base class pointer
  90.     into a derived class pointer so that the derived class's member functions
  91.     can be called?
  92.  A. Syntactically this is allowable. There is always the possibility of
  93.     a base pointer actually pointing to a base class. If this is
  94.     typecast to a derived type, the function being called may not exist
  95.     in the base class. Therefore, you would be grabbing the address of
  96.     a function that does not exist.
  97.  
  98.  Q: What's the difference between the keywords STRUCT and CLASS?
  99.  A: The members of a STRUCT are PUBLIC by default, while in CLASS,
  100.     they default to PRIVATE. They are otherwise functionally equivalent.
  101.  
  102.  Q: I have declared a derived class from a base class, but I can't access any
  103.     of the base class members with the derived class function.
  104.  A: Derived classes DO NOT get access to private members of a base class.
  105.     In order to access members of a base class, the base class members must
  106.     be declared as either public or protected. If they are public, then
  107.     any portion of the program can access them. If they are protected, they
  108.     are accessible by the class members, friends, and any derived classes.
  109.  
  110.  Q: How can I use the Paradox Engine 1.0 with C++?,
  111.  A: Because the Paradox Engine functions are all compiled as C functions,
  112.     you will have to assure that the names of the functions do not get
  113.     "mangled" by the C++ compiler. To do this you need to prototype the
  114.     Engine functions as extern "C". (Name mangling and the use of extern "C"
  115.     are both described in detail in the Borland C++ Programmer's Guide.)
  116.     In the pxengine.h header file insert the following code at the lines
  117.     indicated.
  118.  
  119.        /* inserted at line # 268 */
  120.        #ifdef __cplusplus
  121.        extern "C" {
  122.        #endif
  123.  
  124.        /* inserted at line # 732, just before the final #endif */
  125.        #ifdef __cplusplus
  126.        }
  127.        #endif
  128.  
  129.     Paradox Engine version 2.0 is "aware" of C++ and thus does not require
  130.     any modifications to its header file.
  131.  
  132.  Q: I have a class that is derived from three base classes. Can I insure that
  133.     one base class constructor will be called before all other constructors?
  134.  A: If you declare the base class as a virtual base class, its constructor
  135.     will be called before any non-virtual base class constructors. Otherwise
  136.     the constructors are called in left-to-right order on the declaration
  137.     line for the class.
  138.    
  139.  Q: Are the standard library I/O functions still available for use with
  140.     the C++ iostreams library?
  141.  A: Yes, using
  142.  
  143.        #include <stdio.h>
  144.  
  145.     functions such as printf() and scanf() will continue to be
  146.     available. However, using them in conjunction with stream oriented
  147.     functions can lead to unpredictable behaviour.
  148.  
  149.  Q: When debugging my program in Turbo Debugger, I notice that none of my
  150.     inline functions are expanded inline. Instead, they are all done as
  151.     function calls.
  152.  A: Whenever you compile your program with debugging information included,
  153.     no functions are expanded inline. To verify that your inline functions
  154.     are indeed expanding inline, compile a module with the -S flag of the
  155.     command-line compiler, then examine the .ASM file that is generated.
  156.  
  157.  Q. In C++, given two variables of the same name, one local and one global,
  158.     how do I access the global instance within the local scope?
  159.  A. Use the scope (::) operator. For example:
  160.  
  161.        int x = 10;
  162.        for(int x=0; x < ::x; x++)
  163.        {
  164.            cout << "Loop # " << x << "\n"; // This will loop 10 times
  165.        }
  166.  
  167.  Q. Will the following two functions be overloaded by the compiler, or
  168.     will the compiler flag it as an error? Why?
  169.         void test( int x, double y); and  int test( int a, double b);
  170.  A. The compiler will flag this as a redeclaration error because
  171.     neither return types nor argument names are considered when determining
  172.     unique signatures for overloading functions. Only number and type
  173.     of arguments are considered.
  174.  
  175.  Q. If I pass a character to a function which only accepts an int,
  176.     what will the compiler do? Will it flag it as an error?
  177.  A. No. The compiler will promote the char to an int and use the integer
  178.     representation in the function instead of the character itself. The
  179.     exception here is in the case of a template function, where no implicit
  180.     conversions or promotions take place.
  181.  
  182.  Q. I was trying to allocate an array of function pointers using the new
  183.     operator but I keep getting declaration syntax errors using the following
  184.     syntax:  new int(*[10])();   What's wrong?
  185.  A. The new operator is a unary operator and binds first to the int keyword
  186.     producing the following:  (new int) (*[10])();
  187.     You need to put parentheses around the expression to produce the
  188.     expected results:  new (int (*[10]()); //array of function pointers
  189.  
  190.  Q. What are inline functions? What are their advantages? How are they
  191.     declared?
  192.  A. An inline function is a function which gets textually inserted by
  193.     the compiler, much like macros. The advantage is that execution time
  194.     is shortened because linker overhead is minimized. They are declared
  195.     by using the inline keyword when the function is declared:
  196.  
  197.        inline void func(void) { cout << "printing inline function \n"; }
  198.  
  199.     or by including the function declaration and code body within a class:
  200.  
  201.        class test
  202.        {
  203.        public:
  204.        void func(void) { cout << "inline function within a class.\n"}
  205.        };
  206.  
  207.  Q. If I don't specify either public or private sections in a class,
  208.     what is the default?
  209.  A. In a class, all members are private by default if neither public nor
  210.     private sections are declared.
  211.  
  212.  Q. If I don't specifiy either the public or private keyword when
  213.     inheriting from a base class, what is the default?
  214.  A. In Borland C++ 2.0, the default is public inheritance, but in versions
  215.     3.0 and 3.1, the default is private inheritance.
  216.  
  217.  Q. What does the _seg modifier do?
  218.  A. Using _seg causes a pointer to become a storage place for a
  219.     segment value, rather than an offset ( or a segment/offset ).
  220.     For instance, if "int _seg *x" contains the value 0x40,
  221.     then when you use "*x", the value pointed to will be at
  222.     segment 0x40, offset 0. If you add a value to the pointer,
  223.     the value is multiplied by the size of the pointer type. That
  224.     new value is used as an offset, and is combined with the segment
  225.     value contained in the pointer. For instance,
  226.  
  227.        int _seg *x;
  228.        int value;
  229.  
  230.        x = (int _seg *)0x40;
  231.        value = *(x + 20);
  232.  
  233.     value is assigned the value of the integer at 0x40:0x28
  234.     (Remember, 20 * sizeof(int) = 40 = 0x28).
  235.  
  236.     You can find a more detailed description of _seg in the Borland C++
  237.     Programmer's Guide, Chapter 9.
  238.  
  239.  Q. Can I statically allocate more than 64K of data in a single module?
  240.  A. Yes. Far data items are now supported:
  241.  
  242.        ...
  243.        char far array1[60000L];
  244.        char far array2[60000L];
  245.        ...
  246.  
  247.     For arrays larger than 64k use:
  248.  
  249.        char huge array3[100000L];
  250.  
  251.  Q. What is a friend member function?
  252.  A. Declaring a friend gives non-members of a class access to the
  253.     non-public members of a class.
  254.  
  255.  Q. Why do I get a "Type name expected" error on my definition of a
  256.     friend class in my new class?
  257.  A. You need to let the compiler know that the label you use for your
  258.     friend class is another class. If you do not want to define your
  259.     entire class, you can simply have "class xxx", where xxx is your
  260.     label. For example:
  261.  
  262.     class Boo; //forward class declaration is required
  263.  
  264.     class Foo{
  265.           friend class Boo;
  266.           ...
  267.     };
  268.  
  269.  Q: How can I output hex values in upper case using the iostream libraries?
  270.  A: You need to set the state of the stream using setf(). For example,
  271.  
  272.        #include <iostream.h>
  273.  
  274.        int main(void)
  275.        {
  276.           cout << hex;
  277.           cout << "\nNot upper-case : " << 255;
  278.           cout.setf(ios::upper-case);
  279.           cout << "\nUppercase     : " << 255;
  280.           return 0;
  281.         }
  282.  
  283.  Q. What is the "this" pointer?
  284.  A. "this" is a local variable in the body of a non-static member function.
  285.     It is a pointer to the object for which the function was invoked. It
  286.     cannot be used outside of a class member function body.
  287.  
  288.  Q. Why does a binary member function only accept a single argument?
  289.  A. The first argument is defined implicitly.
  290.  
  291.  Q. Looking through the class libraries there are definitions in classes
  292.     which look like:
  293.        class test {
  294.            int funct( void ) const;
  295.        };
  296.     What is the const keyword doing here?
  297.  A. There is a pointer to the object for which a function is called
  298.     known as the 'this' pointer.  By default the type of 'this'
  299.     is  X *const ( a constant pointer).  The const keyword changes the
  300.     type to const X *const ( a constant pointer to constant data ).
  301.  
  302.  Q: I want to use _new_handler and set_new_handler.
  303.  A: Borland C++ supports _new_handler and set_new_handler.
  304.     You can find a discussion of them in Chapter 3 of the Borland C++
  305.     Programmer's Guide. The type of _new_handler is as follows.
  306.         typedef void (*vfp)(void);
  307.         vfp _new_handler;
  308.         vfp set_new_handler( vfp );
  309.  
  310.  Q: I would like to use C++ fstreams on a file opened in binary mode,
  311.     how is this done?
  312.  A: Use ios::binary as the open mode for the file:
  313.         #include <fstream.h>
  314.         ifstream binfile;
  315.         binfile.open("myfile.bin", ios::binary);
  316.  
  317.  Q: How can I get at the DOS file handle associated with my iostream?
  318.  A: Using a combination of member functions fd() and rdbuf() you can
  319.     get at the file handle.
  320.         #include <fstream.h>
  321.         #define fstrno(s)  (((s).rdbuf())->fd())
  322.         ifstream test("test.txt");
  323.         cout << "handle is " << fstrno(test) << '\n';
  324.  
  325.  Q: How can I increase the number of FILES available to my program under
  326.     Borland C++ 3.1?
  327.  A: Increasing the number of available files involves changing the
  328.     following 3 files located in the Run-Time Library: _NFILE.H,
  329.     FILES.C, and FILES2.C. For instructions on how to do this, download
  330.     TI870 from the Borland fax line.
  331.  
  332.  Q: When using the BIDS library, if I try to create an Array or Bag of
  333.     integers, I get the error "multiple declaration for detach()...".
  334.  A: If you try to create a BI_ArrayAsVector<int>, BI_SArrayAsVector<int>,
  335.     or BI_BagAsVector<unsigned>, the compiler will yield an error message.
  336.     This is because each of these templates provides a version of detach()
  337.     that takes an argument whose type is the type for which the template is
  338.     being instantiated, plus a version that takes an argument of type int or
  339.     unsigned int, which lets you specify the index for the item to be detached.
  340.     Therefore, when instantiated with an integer, these two versions have
  341.     the same signature, which is what causes the error. Integer types are
  342.     not allowed here due to resulting ambiguity between the type and the
  343.     index of the Bag or Array.
  344.  
  345.  Q: How do I get DPMI programs like BC++ 3.0 and 3.1 to run in a DOS 
  346.     session under OS/2 2.0?
  347.  A: The DPMI programs within BC++ 3.0 and 3.1 can be run under
  348.     OS/2 2.0 in a DOS (MVDM) session if the DPMI_DOS_API flag is enabled.
  349.     To set this, pull up the menu for the DOS icon with the right mouse
  350.     button, then mouse click on the arrow button appearing to the right
  351.     of the OPEN menu choice.  Choose SETTINGS from the resulting menu,
  352.     then go to the SESSION tab of the notebook and click on the DOS
  353.     SETTINGS button. Highlight DPMI_DOS_API in the listbox. Finally, make
  354.     sure ENABLED is chosen in the upper right pulldown listbox, and save.
  355.  
  356.  Q: How come the bioscom() function does not work on my computer?
  357.  
  358.  A: bioscom() uses DOS interrupt 0x14 directly, and thus bioscom()'s
  359.     functionality is tied directly to the BIOS of your computer.  MS-DOS
  360.     support for the serial communications port may be inadequate in several
  361.     respects for high-performance serial I/O applications.  First, MS-DOS
  362.     provides no portable way to test for the existence or status of a
  363.     particular serial port in a system.  If a program "opens" COM2 and
  364.     writes data to it, and the physical COM2 adapter is not present in the
  365.     system, the program may simply hang.  Similarly, if the serial port
  366.     exists, but no character has been received and the program attempts to
  367.     read a character, the program will hang until one is available.  There
  368.     is no traditional function call to check if a character is waiting.
  369.     MS-DOS also provides no portable method to initialize the communication
  370.     adapter to a particular baud rate, word length, and parity.  An
  371.     application must resort to ROM BIOS calls, manipulate the hardware
  372.     directly, or rely on the user to configure the port properly with the
  373.     MODE command before running the application that uses it.  Because of
  374.     all the problems mentioned above, we strongly recommend getting a third
  375.     party communications package when attempting to do serial communications,
  376.     or downloading the example program SERIAL.ZIP from our BBS at (408)
  377.     439-9096.
  378.  
  379.  
  380.  C o m m o n    W i n d o w s   Q u e s t i o n s
  381.  ----------------------------------------------------------------------
  382.  Q. Why isn't my DLL working correctly?
  383.  A. One possibility is that you are not linking in the correct 'cw'
  384.     library.  If you are building a small model DLL, you should be using
  385.     cwc, not cws.  If you are building a medium model DLL, you should
  386.     be using cwl, not cwm.  Compact and large models should use cwc
  387.     and cwl respectively.
  388.  
  389.  Q. I have a project that works fine using Borland C++ 2.0. When I use
  390.     Borland C++ 3.1, the linker cannot find my cwinX.lib file, where X
  391.     corresponds to the memory model I am using. What's wrong?
  392.  A. Borland C++ 3.1 uses different library names than Borland C++ 2.0.
  393.     Instead of cwinX.lib, use cwX.lib in your project files, when using
  394.     Borland C++ 3.1.
  395.  
  396.  Q. Why isn't my program working correctly?  I'm getting a message box from
  397.     Windows saying "Unrecoverable Application Error".
  398.  A. One possible answer is that the program was not built correctly.
  399.     For example, the linker did not get the correct information to export
  400.     functions.  Diagnostic messages from the linker could indicate this.
  401.     To check that you have built your program on DLL as expected, review
  402.     the section in Chapter 8 of the Programmer's Guide that deals with 
  403.     exports. This section has a table with 8 columns describing the possible
  404.     combinations you might have used to build your program.  If the setup
  405.     of your program corresponds to one of the last three columns, chances
  406.     are that your program was not built correctly ( or, at least, as you
  407.     intended ). Column 5 corresponds to the 'classical' method of building
  408.     Windows programs (that is, all exports are declared in the module
  409.     definition file (the .def file )).
  410.  
  411.     The columns that use -WE or -WDE will build 'better' code in sense that
  412.     the compiler will not make 'exportable' any functions that it does not
  413.     actually export.  However, it is here that many people will run into
  414.     problems.  If you have any functions declared as exports in the .def
  415.     file but the module is compiled with -WE or -WDE, then you probably
  416.     have built the program incorrectly (the function will be exported only
  417.     if it is preceded by _export in the source code).
  418.  
  419.  Q. How do I use the _export key word?
  420.  A. Put the "_export" immediately before the function name in the function
  421.     declaration to export that function.
  422.     Here is a quick example:
  423.        long FAR PASCAL _export func(void) {...}
  424.  
  425.  Q. I tried to run <filename>.EXE under Windows 3.0. A window popped up
  426.     titled 'Application Compatibility Warning', and said,
  427.        'The application you are about to run... '.
  428.  A. You did not run the resource compiler, i.e.,
  429.        C:> RC <filename>.RC
  430.     at the command line at the time you created this program.  If you plan
  431.     to create a menu with menuitems in your window, you will need to create
  432.     an RC file.  If your program has menus and is a simple window that does
  433.     not need an RC file, run the resource compiler with <filename>.EXE.
  434.  
  435.  Q. I ran the resource compiler and got the error message:
  436.        RC: fatal error RW1010: Could not open <filename>.RC
  437.  A. You do not have an RC file created for <filename>. If you do not need
  438.     an RC file for this particular application, run the resource compiler
  439.     with <filename>.EXE.  This will create an application that will be able
  440.     to run on Windows 3.0.
  441.  
  442.  Q. I run BCC.EXE and then RC.EXE and get the error message:
  443.        RC: warning RW4002: Non-discardable segment # set to PRELOAD
  444.  A. If # equals 1, then you forgot the CODE PRELOAD statement in your
  445.     <filename>.DEF file.  If # equals 2, then you forgot the DATA PRELOAD
  446.     statement in your <filename>.DEF file.  If two of these warnings occur,
  447.     you have either forgotten both CODE and DATA statements or have not
  448.     created a <filename>.DEF file.
  449.  
  450.  Q. I run RC.EXE and get the error message:
  451.        RC: fatal error RW1030: <filename>.EXE: Unable to open
  452.  A. You need to list more information after the CODE statement in your
  453.     <filename>.DEF file (that is, CODE PRELOAD).
  454.  
  455.  Q. I run BCC.EXE and get the error message:
  456.        Fatal: <filename>.def (<line #>): syntax error
  457.  A. Check your DATA statement on line number # in <filename>.DEF for the
  458.     correct code (that is, DATA PRELOAD).
  459.  
  460.  Q. I run the Borland C++ IDE directly from Windows, rather than from the
  461.     DOS command line.  It does not get a DOS path and cannot find the
  462.     resource compiler RC, as that transfer item does not have an explicit
  463.     path listed.
  464.  A. Either run from a DOS shell (i.e., start DOS, then start Borland C++) or
  465.     modify the path for the transfer item so it explicitly knows where RC.EXE
  466.     lives.
  467.  
  468.  Q. What is new in Windows 3.1 programming?
  469.  A. The file WIN31.DOC, found in the DOC directory, describes new
  470.     techniques for writing Windows 3.1 applications as well as how to
  471.     convert Windows 3.0 code to Windows 3.1 code.  There is also a lot of
  472.     very useful documentation in the online Help files.  New functions and 
  473.     messages, OLE, DDEML, Common Dialogs, TOOLHELP and many more topics 
  474.     are covered in the new online Help files.
  475.  
  476.  
  477.  Q. If I use the new compiler, will my application remain compatible with
  478.     Windows 3.0?
  479.  A. The file WIN31.DOC, found in the DOC directory discusses how to
  480.     maintain compatibility with Windows 3.0.
  481.  
  482.  Q. What are WIN30, WIN31, and STRICT?  Why do I get error messages about
  483.     them when I compile?
  484.  A. The symbols WIN30, WIN31, and STRICT are new to Windows 3.1.  They are
  485.     used to control what is defined in the WINDOWS.H header file.  The
  486.     file WIN31.DOC, found in the DOC directory, has additional
  487.     information on these symbols.
  488.  
  489.     The WIN30 and WIN31 symbols help define the version of Windows that
  490.     your application expects to run under.  The STRICT symbol is used to
  491.     enforce stricter data types, which is especially helpful when writing
  492.     C++ code.  When STRICT is defined, WIN31 must also be defined.  To
  493.     make your OWL code strict compliant you will need to change some data
  494.     types, such as the hInstance arguments to WinMain() and the
  495.     TApplication constructor. For example,
  496.  
  497.     int WinMain( HANDLE, HANDLE, LPSTR, int );           // Non STRICT style
  498.     int WinMain( HINSTANCE, HINSTANCE, LPSTR, int );     // STRICT style
  499.  
  500.     To define WIN30, WIN31, or STRICT you can declare them either in your
  501.     code:
  502.  
  503.         #define WIN31
  504.         #define STRICT
  505.  
  506.     at the command line:
  507.  
  508.         -DWIN31 -DSTRICT
  509.  
  510.     or in the IDE (via OPTIONS|COMPILER|CODE GENERATION|DEFINES):
  511.  
  512.         WIN31;STRICT
  513.  
  514.     Note that WIN30 and WIN31 are only meaningful for OWL applications.
  515.     STRICT can be used with and without OWL.
  516.  
  517.  Q. Why do I get a 'suspicious pointer conversion' warning or 'cannot
  518.     convert' error (in C++ code) when I try to use the address of my
  519.     window procedure or call back function?
  520.  A. Windows 3.1 has introduced a new type, WNDPROC, which takes the place
  521.     of the FARPROC type in some cases, such as the data type of the
  522.     lpfnWndProc member of the WNDCLASS structure.  If you are getting a
  523.     warning or error when setting up a WNDCLASS structure that will be
  524.     passed to RegisterClass(), use a WNDPROC cast to resolve the type
  525.     mismatch.  If you were previously using a FARPROC cast, simply change
  526.     it to a WNDCLASS cast. For example,
  527.  
  528.     void FAR PASCAL f( void );
  529.     WNDCLASS wcTemp;
  530.     wcTemp.lpfnWndProc = f;              // Warning in C or error in C++
  531.     wcTemp.lpfnWndProc = (FARPROC)f;     // Windows 3.0 style type cast
  532.     wcTemp.lpfnWndProc = (WNDPROC)f;     // Windows 3.1 style type cast
  533.  
  534.  Q. How can I use the new features of Windows 3.1 in my applications?
  535.  A. There are a number of examples that shipped with the new compiler
  536.     that use the new features of Windows 3.1, such as OLE, DDEML and
  537.     Common Dialogs.  There are also lengthy descriptions of programming
  538.     techniques for the new features of Windows 3.1 in the online Help
  539.     files.
  540.  
  541.  Q. Why don't some of the new Windows 3.1 API functions, such as
  542.     ChooseColor(), do anything when I call them?
  543.  A. The new Windows 3.1 functions that are passed structures as parameters
  544.     require that the size field of the structure be initialized to the size
  545.     of the structure.  This technique allows for backward compatability in
  546.     future versions of these functions.  If the size field is not set
  547.     correctly the function will not do anything. For example,
  548.  
  549.     CHOOSECOLOR ccTemp;                          // Data structure
  550.     ccTemp.lStructSize = sizeof( ccTemp );       // Set the size first!
  551.     if( ChooseColor( &ccTemp ) != 0 ) etc . . .  // Then call the function
  552.  
  553.  Q. Why is my DDEML application crashing?
  554.  A. DDEML can crash in seemingly random ways if the conversation handle
  555.     or application instance identifier is incorrect or corrupted.   Use
  556.     TDW to watch the value of the conversation handle and the application
  557.     instance identifier.  If it changes, is corrupted, or you
  558.     inadvertently pass the DDE Management Library an invalid value, that
  559.     particular call may not fail but DDEML may become unstable and crash
  560.     at some time in the future.  Also note that before DdeInitialize() is
  561.     called for the first time, the application instance identifier
  562.     argument MUST be set to 0.
  563.  
  564.  
  565.  I n t e g r a t e d    E n v i r o n m e n t
  566.  ----------------------------------------------------------------------
  567.  Q: Why doesn't my mouse work well with Borland C++?
  568.  A: The most likely cause is that you are using an older mouse driver. 
  569.     You'll need to get a newer version.  Driver versions required for 
  570.     full compatibility include:
  571.         Logitech driver 5.01+, Microsoft 7.04+, Genius 9.06+.
  572.  
  573.  
  574.  Q. Why is Borland C++ not able to find any of my #include files?
  575.  A. The compiler searches for include files in the Borland C++ Include
  576.     Directories path. You can specify this path through the
  577.     Options|Directories menu. The INSTALL program initially sets this
  578.     path to the directory where it copied all the Borland C++ *.h files.
  579.  
  580.  Q. Why do I get the message:
  581.        Linker Error: Unable to open input file 'C0x.OBJ'
  582.  A. The linker searches for Borland C++ start-up and library files in the
  583.     Borland C++ Library Directories path. You can specify this path through
  584.     the Options|Directories menu. The INSTALL program initially sets this
  585.     path to the directory where it copied the start-up and library files.
  586.     Also be sure that you installed the memory model that the linker
  587.     is looking for. The 'x' in the error message corresponds to the memory
  588.     model, e.g. 's' for small, 'l' for large, etc.
  589.  
  590.  Q. How do I get Borland C++ to link in my own libraries or use multiple
  591.     source files?
  592.  A. Borland C++'s Project Manager is designed to allow you to work with
  593.     multiple files.
  594.  
  595.  Q. Why does the linker tell me that all the graphics library routines
  596.     are undefined?
  597.  A. The Options|Linker|Libraries|Graphics Library item must be set ON
  598.     if you are using any Borland C++ graphics functions and have not
  599.     specified GRAPHICS.LIB in a project file.
  600.  
  601.  Q. Why does Borland C++ report "Unable to open include file 'stdarg.h'"
  602.     when I try to #include <stdio.h>?
  603.  A. The most probable reason is that you have exceeded the number
  604.     of files that DOS can have open simultaneously. Add the line
  605.  
  606.        FILES=20
  607.  
  608.     to your DOS CONFIG.SYS file. This allows DOS to open up to 20
  609.     files at the same time. CONFIG.SYS will only be effective after
  610.     you have rebooted your computer. See the IBM DOS Reference
  611.     Manual for details on the CONFIG.SYS file.
  612.  
  613.  Q. I run BC.EXE directly from Windows, rather than from the
  614.     DOS command line.  It does not get a DOS path and cannot find the
  615.     resource compiler RC, as that transfer item does not have an explicit
  616.     path listed.
  617.  A. Either run from a DOS shell (i.e., start DOS, then start Borland C++)
  618.     or modify the path for the transfer item so it explicitly knows where
  619.     RC.EXE lives.
  620.  
  621.  Q. Where is the BCINST.EXE utility I have used in previous versions
  622.     of the compiler?
  623.  A. The capabilities of BCINST have been incorporated into other areas
  624.     of the product and thus BCINST is no longer necessary.  To remap
  625.     key bindings, use the Turbo Editor Macro Compiler (TEMC).  Colors
  626.     can be changed from within the IDE under Options | Environment | Colors.
  627.  
  628.  Q. When I Make, Run, or Trace a program, Borland C++ sometimes goes
  629.     through the compile and link process even when the object files
  630.     are up-to-date.
  631.  A. Borland C++'s MAKE logic works solely on a file's date and time
  632.     stamp. If one of your source files is marked with a date
  633.     that's sometime in the future, the object files that are
  634.     created from it will always be older than the source file,
  635.     and Borland C++ will always try to rebuild the file. You can fix
  636.     this by using TOUCH.COM to set the file to the current date
  637.     and time. You should also make sure that your system's date
  638.     and time are always properly set. TOUCH.COM is documented in
  639.     the file UTIL.DOC.
  640.  
  641.  Q. How come my old Turbo C project files don't work anymore?
  642.  A. Project files now contain much more information about a project now,
  643.     and hence are no longer stored in ASCII format. To create a project
  644.     file, select PROJECT from the main menu, and follow the menus. To
  645.     convert your old project files to the new format, use the supplied
  646.     utility file PRJCNVT.EXE (documented in UTIL.DOC).
  647.  
  648.  Q. How can I convert my Turbo C 2.0 project files to the new
  649.     format?
  650.  A. There is a conversion utility in your Borland C++ BIN directory
  651.     called PRJCNVT.EXE. This program will perform the conversion.
  652.  
  653.  Q. How come my project file is automatically loaded when I start Borland C++?
  654.     I want to work on a different program.
  655.  A. If there is only one project file in the current directory, Borland C++
  656.     will load and use that one file. If there are no project files, or
  657.     if there are multiple project files, Borland C++ does not automatically
  658.     load one. Go ahead and create a new project. To use a specific project
  659.     file, you can specify the name of that project file on the command
  660.     line used to start Borland C++. For example, 'bc farley.prj' would
  661.     start up BC++ and load the 'farley' project.
  662.  
  663.  Q. My right mouse button appears to do nothing. Can I change this so it
  664.     will set breakpoints?
  665.  A. Yes, under the menu for Options|Environment|Mouse there is a
  666.     dialog box for the right mouse button. You can change it to set
  667.     breakpoints, or to do many other things.
  668.  
  669.  Q. How can I find out where my "null pointer assignment" is occurring?
  670.  A. Set a watch on the following expressions:
  671.  
  672.             *(char *)0,4m
  673.             (char *)4
  674.  
  675.     Step through the program. When the values change, the just-executed line
  676.     is the one that is causing the problem.
  677.  
  678.  Q. When I compile my program, I get the following error:
  679.  
  680.        Error: C:\BORLANDC\INCLUDE\STDIO.H: Overlays only supported in
  681.        medium, large, and huge memory models
  682.  
  683.     What is happening?
  684.  A. The Overlay Support option has been selected and does not work
  685.     in the tiny, small, or compact memory models. You can turn this option
  686.     off with:
  687.       Options | Compiler | Code Generation | Overlay Support
  688.  
  689.     Also note that overlays are not supported under Windows.
  690.    
  691.  Q. When I try to load a new file after editing a file, the first
  692.     file remains on the screen. How do I close the first file?
  693.  A. Use Alt-F3 (or Ctrl-F4) to close the current file. Also, use 
  694.     F6 to move from one file to the next, if there is more than 
  695.     one file open at a time.
  696.  
  697.  Q. I'm doing a search and replace operation, and the editor prompts me for
  698.     each replacement. I've selected "Change All", but it still does it.
  699.  A. To disable the prompting, you must unselect the "Prompt on replace"
  700.     option on the left side of the dialog box.
  701.  
  702.  Q. When I try to use the any of the pseudo registers, like _AX, I
  703.     get the error message "Undefined symbol '_AX' in function..."
  704.     when I compile. Why?
  705.  A. You are only allowed to use the pseudo registers in the Borland
  706.     C++ and ANSI modes of the compiler. You can change this setting
  707.     in the Options | Compiler | Source menu.
  708.  
  709.  Q. Since I don't have a mouse, can I still copy blocks of code
  710.     from one file to another?
  711.  A. Yes. You can mark the beginning and end of a block by moving
  712.     to the appropriate area and pressing Ctrl-K-B (mark beginning) and
  713.     Ctrl-K-K (mark end). You can then use the copy and paste commands
  714.     in the Edit menu.
  715.  
  716.  Q: How do I stop all of the files I have ever edited from constantly
  717.     being open when I bring up Borland C++?
  718.  A: By default, Borland C++ saves what is called the desktop configuration.
  719.     This configuration is saved in a file with a .DSK extension.  By deleting
  720.     any files of this type (usually located in the current directory and/or
  721.     the BORLANDC\BIN directory), then entering Options/Environment/Preferences
  722.     and removing the check from 'auto save desktop', you will begin with a
  723.     clean desktop each time you invoke Borland C++.
  724.  
  725.  Q: How do I view 32-bit registers when I compile my code with Options|
  726.     Compiler|Advanced Code Generation|Instruction Set|80386 set?
  727.  A: Add the appropriate 32-bit register psuedovariable to the Watch 
  728.     window. For example, if you were interested in the value of EAX,
  729.     you'd add _EAX to the Watch window.
  730.  
  731.  C o m m a n d  -  L i n e    C o m p i l e r
  732.  ----------------------------------------------------------------------
  733.  Q. Why is Borland C++ not able to find any of my #include files?
  734.  A. The compiler searches for include files in the Borland C++ Include
  735.     Directories path. You specify this path with the -I option. The INSTALL
  736.     program initially writes a configuration file (TURBOC.CFG) that
  737.     sets this path to the directory where it copied all the Borland C++
  738.     *.h files. You may edit this file to change the default path, or create
  739.     this file in your current working directory and place any relevant paths
  740.     and other command line compiler options in it. A sample turboc.cfg file
  741.     may contain the following:
  742.        -ml
  743.        -IC:\BC31\INCLUDE;C:\BC31\CLASSLIB\INCLUDE
  744.        -LC:\BC31\LIB;C:\BC31\CLASSLIB\LIB
  745.  
  746.  Q. Why do I get the message:
  747.        Linker Error: Unable to open input file 'C0x.OBJ'
  748.  A. The linker searches for Borland C++ start-up and library files in the
  749.     Borland C++ Library Directories path. You can specify this path with
  750.     the -L option. If you allow BCC to invoke the linker, it will search
  751.     the directories in the configuration file (TURBOC.CFG) written by the
  752.     INSTALL program (see above). If you run TLINK, the configuration file
  753.     is not read. TLINK does use the configuration file TLINK.CFG, so you can
  754.     specify library paths in this file.
  755.  
  756.  Q. Why does the linker tell me that all the graphics library routines are
  757.     undefined?
  758.  A. BCC will not search the graphics library unless you tell it to.
  759.     You should specify the graphics library on the command line. For
  760.     example, to compile BGIDEMO, type
  761.  
  762.        BCC BGIDEMO.C GRAPHICS.LIB<Enter>
  763.  
  764.  Q. I run BCC.EXE and get the error message:
  765.        Fatal: <filename>.def (<line #>): syntax error
  766.  A. Check your DATA statement on line number # in <filename>.def for the
  767.     correct code (that is, DATA PRELOAD).
  768.  
  769.  
  770.  G e n e r a l     I / O
  771.  ----------------------------------------------------------------------
  772.  Q. The '\n' in cprintf() does not return the cursor to the
  773.     beginning of the line. It only moves the cursor down one line.
  774.  A. cprintf() interprets '\n' as a Line Feed. To force the cursor to
  775.     the beginning of the line, manually insert a Carriage Return:
  776.  
  777.       cprintf("\n\r");
  778.  
  779.  Q. How do I print to the printer from a Borland C++ program?
  780.  A. Borland C++ uses a FILE pointer (stdprn) defined in the STDIO.H
  781.     file. You do not need to open stdprn before using it:
  782.  
  783.        #include <stdio.h>
  784.        int main(void)
  785.        {
  786.            fprintf(stdprn, "Hello, printer!\n");
  787.        }
  788.  
  789.     Note that if your printer is line-buffered, the output is
  790.     flushed only after a '\n' is sent.
  791.  
  792.  Q. I am reading and writing binary files. My program is translating
  793.     the Carriage Return (0x0D) and Line Feed (0x0A) characters. How do
  794.     I prevent this from happening?
  795.  A. Files opened in text mode will translate these characters for
  796.     DOS. To read a file in binary mode, open it in binary mode.
  797.     For example,
  798.  
  799.       #include <stdio.h>
  800.       int main(void)
  801.       {
  802.          FILE *binary_fp;
  803.          char buffer[100];
  804.  
  805.          binary_fp = fopen("MYFILE.BIN", "rb");
  806.  
  807.          fread(buffer, sizeof(char), 100, binary_fp);
  808.  
  809.                     :
  810.       }
  811.  
  812.     The default file mode is text.
  813.  
  814.  Q. Why don't printf() and puts() print text in color?
  815.  A. Use the console I/O functions cprintf() and cputs() for color output.
  816.  
  817.       #include <conio.h>
  818.       int main(void)
  819.       {
  820.           textcolor(BLUE);
  821.           cprintf("I'm blue.");
  822.       }
  823.  
  824.  Q. How do I print a long integer?
  825.  A. Use the "%ld" format:
  826.  
  827.       long int l = 70000L;
  828.       printf("%ld", l);
  829.  
  830.  Q. How do I print a long double?
  831.  A. Use the "%Lf" format.
  832.  
  833.       long double ldbl = 1E500;
  834.       printf("%Lf", ldbl);
  835.  
  836.  
  837.  E x a m p l e   P r o g r a m s
  838.  ----------------------------------------------------------------------
  839.  Q. How do I compile and run the BGIDEMO program?
  840.  A. 1. Make sure that the following Borland C++ files are in your
  841.        current directory:
  842.  
  843.          BGIDEMO.C
  844.          *.BGI
  845.          *.CHR
  846.  
  847.        OR change the third parameter of the initgraph() function call to
  848.        the full directory path to the location of the above files (using
  849.        double backslashes). For example:
  850.  
  851.            initgraph(&gdriver, &gmode, "c:\\borlandc\\bgi");
  852.  
  853.     2. Run Borland C++.
  854.  
  855.     3. Load BGIDEMO.C into the Editor by pressing F3, then typing
  856.        BGIDEMO<Enter>
  857.  
  858.     3. Go to the Run menu and choose the Run item.
  859.  
  860.  Q. How do I create a COM file?
  861.  A. DOS versions 3.2 and earlier include an EXE2BIN utility that
  862.     converts EXE files to COM files. Users who do not have EXE2BIN can
  863.     use TLINK, the Borland C++ command-line linker, to create a COM file
  864.     instead of an EXE file. Use the /t option. For example:
  865.  
  866.        BCC -mt -lt tiny
  867.  
  868.     will create TINY.COM instead of TINY.EXE. The -l switch passes
  869.     the /t argument to the linker in this case.
  870.  
  871.     There are certain limitations in converting an EXE file to a COM
  872.     file. These limitations are documented in the IBM Disk Operating
  873.     System manual under EXE2BIN.
  874.  
  875.     Borland C++'s TINY model is compatible with the COM format, but programs
  876.     that use Borland C++'s floating-point routines cannot be used in a
  877.     TINY model application.
  878.  
  879.  Q: The following program compiles/links successfully in C but
  880.     not in C++.  Why?
  881.  
  882.     #include <stdlib.h>
  883.  
  884.     int compare(const int *one, const int *two)
  885.     {
  886.        if (*one > *two)
  887.           return  -1;
  888.        else
  889.           return 1;
  890.     }
  891.  
  892.     int a[3] = { 50, 10, 20 };
  893.  
  894.     void main()
  895.     {
  896.          qsort(a, 3, sizeof(a[0]), compare);
  897.     }
  898.  
  899.  A: The fourth parameter to compare is the function pointer, and
  900.     here's how it's declared in stdlib.h:
  901.  
  902.     void qsort (void *__base, size_t __nelem, size_t __width,
  903.                 int _Cdecl (*__fcmp)(const void *, const void *));
  904.  
  905.     However, the above program WILL NOT compile in C++, because of the
  906.     strong typing features of the C++ language.  The compiler refuses to
  907.     convert the void parameters in the declaration to __fcmp function to
  908.     int parameters. However, because C++ permits casting of function pointers,
  909.     you can fix the call to QSORT in C++ like this:
  910.  
  911.     qsort(a, 3, sizeof(a[0]), (int (*)(const void *,const void *))compare);
  912.  
  913.     By casting the COMPARE function to be of the same type as the
  914.     declaration in stdlib.h, C++ will accept and compile it.
  915.  
  916.  Q: How can I allocate a doubly dimensioned array?
  917.  A: You may use either malloc() with C or C++, or the new operator with
  918.     C++:
  919.  
  920.     malloc():  to create a 2 by 3 character array
  921.  
  922.         int i;
  923.         char** p;
  924.         p = (char **) malloc(2);
  925.         for (i=0; i<2; i++) p[i] = (char *) malloc(3);
  926.  
  927.     new:
  928.  
  929.         int j;
  930.         char** q;
  931.         q = new char* [2];
  932.         for (j=0; j<2; j++) q[j] = new char [3];
  933.  
  934.  
  935.  
  936.  
  937.  G r a p h i c s
  938.  ----------------------------------------------------------------------
  939.  Q. Why do I get the error message:
  940.  
  941.        BGI Error: graphics not initialized (use 'initgraph')
  942.  
  943.     when I use a graphics function? My program has already
  944.     called initgraph().
  945.  A. For some reason initgraph() failed. To find out why, check
  946.     the return value of graphresult(). For example:
  947.  
  948.       #include <graphics.h>
  949.       int main(void)
  950.       {
  951.         int gerr;   /* graphics error */
  952.         int gdriver = DETECT, gmode;
  953.  
  954.         /* Initialize graphics using auto-detection and look
  955.            for the .BGI and .CHR files in the C:\BORLANDC\BGI directory.
  956.         */
  957.         initgraph(&gdriver, &gmode, "C:\\BORLANDC\\BGI");
  958.  
  959.         if ((gerr = graphresult()) != grOk)
  960.         {
  961.             printf("Error : %s\n", grapherrormsg(gerr));
  962.             exit(1);
  963.         }
  964.                :
  965.       }
  966.  
  967.  
  968.  
  969.  M a t h  /  F l o a t i n g    P o i n t
  970.  ----------------------------------------------------------------------
  971.  Q. Why do I get incorrect results from all the math library
  972.     functions like cos(), tan() and atof()?
  973.  A. You must #include <math.h> before you call any of the standard
  974.     Borland C++ math functions. In general, Borland C++ assumes that a function
  975.     that is not declared returns an int. In the case of math functions,
  976.     they usually return a double. For example
  977.  
  978.         /* WRONG */                       /* RIGHT */
  979.                                           #include <math.h>
  980.         int main(void)                    int main(void)
  981.         {                                 {
  982.           printf("%f", cos(0));             printf("%f", cos(0));
  983.         }                                 }
  984.  
  985.  Q. How do I "trap" a floating-point error?
  986.  A. See the signal() and matherr() functions in the Borland C++ Library
  987.     Reference. The signal() function may be used to trap errors in the
  988.     80x87 or the 80x87 emulator. The matherr() function traps errors
  989.     in the Math Library functions.
  990.  
  991.  
  992.  L i n k e r    E r r o r s
  993.  ----------------------------------------------------------------------
  994.  Q. I am linking C functions with C++ functions.  The linker reports that
  995.     all of my C functions are undefined.  Why?
  996.  A. Linking C++ modules with C modules requires the use of a linkage
  997.     specification.  Prototypes for C functions within C++ modules must
  998.     be in one of the following forms:
  999.  
  1000.         extern "C" declaration
  1001.         extern "C" { declarations }
  1002.  
  1003.     For example, if a C module contains functions
  1004.     "char *SCopy(char*, char*);" and "void ClearScreen(void)", they
  1005.     must be declared in a C++ module in one of the following ways:
  1006.  
  1007.         extern "C" char *SCopy(char*, char*);
  1008.         extern "C" void ClearScreen(void);
  1009.  
  1010.     or
  1011.  
  1012.         extern "C" {
  1013.             char *SCopy(char*, char*)
  1014.             void ClearScreen(void);
  1015.         }
  1016.  
  1017.     For further examples, see the standard header files.  For additional
  1018.     comment, see Common C++ Questions.
  1019.  
  1020.  Q. Why do I get the message:
  1021.       Linker Error: Unable to open input file 'C0x.OBJ'
  1022.  A. See the "Integrated Environment" section above.
  1023.  
  1024.  Q. Why do I get the message:
  1025.       Linker Error: Undefined symbol '_main' in module C0
  1026.  A. Every C program must contain a function called main(). This
  1027.     is the first function executed in your program. The function
  1028.     name must be all in lower case. If your program does not
  1029.     have one, create one. If you are using multiple source files,
  1030.     the file that contains the function main() must be one of
  1031.     the files listed in the Project.
  1032.  
  1033.     Note that an underscore character '_' is prepended to all
  1034.     external Borland C++ symbols.
  1035.  
  1036.  Q. Why does the linker tell me that all the graphics library
  1037.     routines are undefined?
  1038.  A. See the "Integrated Environment" and "Command-line Compiler"
  1039.     sections above.
  1040.  
  1041.  Q. What is a 'Fixup overflow'?
  1042.  A. This usually means you are attempting to link object files that were
  1043.     not all compiled under the same memory model. See the listing of TLINK
  1044.     error messages in the Borland C++ Tools and Utilities Guide.
  1045.  
  1046.  Q. I am linking my own assembly language functions with Borland C++.
  1047.     The linker reports that all of my functions are undefined.
  1048.  A. Make sure that you have put an underbar character '_' in front of all
  1049.     assembly language function names to be called by Borland C++. Your
  1050.     assembly language program should be assembled with Case Sensitivity.
  1051.     If compiling as C++ (rather than C), see the "Common C++ Questions"
  1052.     section above which discusses the use of extern "C".
  1053.  
  1054.  Q: I am getting an error out of the linker "segment group exceeds 64K :
  1055.     _text".
  1056.  A: If you are using the BGIOBJ utility, the default segment into which
  1057.     the objects will be place is _text.  You should try using BGIOBJ with
  1058.     the /f option to place the resultant objects into a separate segment.
  1059.     You will then need to use the functions registerfarbgidriver and
  1060.     registerfarbgifont to register the objects for the graphics system.
  1061.     See UTIL.DOC for instructions on using these functions.
  1062.  
  1063.  Q: I am attempting to link Turbo C 2.0 objects into my Borland C++ programs,
  1064.     but continually get unresolved external symbols at link time.
  1065.  A: The names of many of the "helper" functions have changed from what they
  1066.     were in Turbo C 2.0. If you are getting undefined symbols like _LXLSH and
  1067.     _FMUL, this is the problem you are running into.  Your best solution is to
  1068.     get the source code to the old object modules and recompile with Borland
  1069.     C++. The only other possibility would be to extract the helper function
  1070.     objects from the Turbo C 2.0 libraries and link them into the Borland C++
  1071.     program.
  1072.  
  1073.  Q: Why am I getting the error "printf: floating point formats not linked"?
  1074.  A: You probably have your libraries out of order on the tlink command
  1075.     line. Here's how to directly use tlink:
  1076.  
  1077.     tlink <options> <objs>,exe_name,map_name,<libs>
  1078.  
  1079.     <options>:  The options are listed by simply typing TLINK at the command
  1080.                 line.
  1081.  
  1082.     <objs>:     The ordering of the obj's is critical.  The first one must
  1083.                 be c0x (where 'x' corresponds to: s,m,c,l,h depending on
  1084.                 which memory model is being used).  Then the list of the
  1085.                 remaining object files go next.
  1086.  
  1087.     exe_name:   This entry is optional.  If a name is not specified, the
  1088.                 comma MUST be supplied anyway.
  1089.  
  1090.     map_name:   This entry is optional.  If a name is not specified, the
  1091.                 comma MUST be supplied anyway.
  1092.  
  1093.     <libs>:     The ordering of the lib's is critical.  Any user-supplied
  1094.                 and/or third party libraries must be listed first.  If the
  1095.                 program is using any BGI routines, the graphics library must
  1096.                 be next.  Next comes the emu.lib (for emulation) or the
  1097.                 fp87.lib (if you are exclusively planning to use the
  1098.                 coprocessor).  The mathx library comes next, where 'x'
  1099.                 corresponds to the first letter of the memory model in use.
  1100.                 Finally the cx.lib must be last in the list, where 'x'
  1101.                 corresponds to the first letter of the memory model in use.
  1102.  
  1103.     For example, if you are using the large memory model and BGI routines,
  1104.     the tlink line might look like the following:
  1105.  
  1106.            tlink /v c0l myobj,,,mylib graphics emu mathl cl
  1107.  
  1108.     If the object file or library is not in the current directory, the
  1109.     complete pathname must be supplied.  Frequently this causes the command
  1110.     line to exceed 128 characters, which will force the use of a linker
  1111.     response file (this is decribed in the User's Manual).
  1112.  
  1113.  
  1114.  Q. I'm porting an application that uses communal variables to C++.
  1115.     I've set up the compiler to recognize them, but I still get linker
  1116.     errors:
  1117.  
  1118.       Error: <name> defined in module <a> is duplicated in module <b>
  1119.  
  1120.  A. C++ doesn't support explicit COMDEFs; you must use static
  1121.     variables or switch to C.
  1122.  
  1123.  O t h e r    Q u e s t i o n s
  1124.  ----------------------------------------------------------------------
  1125.  Q. I get a "floating point formats not linked" message when I run
  1126.     my program. What can I do about it?
  1127.  A. Floating point formats (for scanf() and related functions) are
  1128.     not always linked, for savings in executable size. To force their
  1129.     inclusion, put the following somewhere in your source files:
  1130.  
  1131.       extern unsigned _floatconvert;
  1132.       #pragma extref _floatconvert
  1133.  
  1134.  Q. How do I change the stack size?
  1135.  A. The size of the stack of a Borland C++ program is determined at
  1136.     run time by the global variable _stklen. To change the size
  1137.     to, for example, 10,000 bytes, include the following line in
  1138.     your program:
  1139.  
  1140.       extern unsigned _stklen = 10000;
  1141.  
  1142.     This statement must not be inside any function definition.
  1143.     The default stack size is 4,096 bytes (4K), and you may increase
  1144.     the stack to 65519 (0xFFEF) or just under 64K in the compact, large,
  1145.     or huge memory models.
  1146.  
  1147.  Q. I'm getting a 'Stack Overflow!' message when I run my program.
  1148.     How can I work around this?
  1149.  A. If you are using the compact, large, of huge memory models, you may
  1150.     increase the stack size by following the procedure above. In the
  1151.     smaller memory models, your only option is to decrease the amount
  1152.     of stack space or near heap space used in your program. Stack
  1153.     overflows are usually caused by a large amount of local data or
  1154.     recursive functions. You can decrease the amount of stack space
  1155.     used in several ways:
  1156.     1) By declaring your local variables static (see the BC++ Programmer's
  1157.        Guide for the effects of using the "static" keyword):
  1158.  
  1159.          int main(void)                int main(void)
  1160.          {                             {
  1161.              char x[5000];     -->          static char x[5000];
  1162.                  :                                :
  1163.          }                             }
  1164.     2) By making your variables global rather than local:
  1165.  
  1166.         char x[5000];    //global allocation above main()
  1167.         int main(void)
  1168.         {
  1169.                :
  1170.         }
  1171.    3) Or by allocating your variables dynamically off the far heap:
  1172.  
  1173.         #include <alloc.h>
  1174.         int main(void)
  1175.         {
  1176.            char far* x;
  1177.            x = (char far*)farmalloc(5000);  //dynamic allocation
  1178.            // or in the case of C++ you can use the new operator
  1179.            // x = new char[5000];
  1180.               :
  1181.         }
  1182.  
  1183.  Q. My program comes up with the message 'Null pointer assignment'
  1184.     after it terminates. What does this mean?
  1185.  A. Before a small-data model Borland C++ program returns to DOS, it will
  1186.     check to see if the beginning of its data segment has been corrupted.
  1187.     This message is to warn you that you have used uninitialized pointers
  1188.     or that your program has corrupted memory in some other way.
  1189.  
  1190.  Q. Why are .EXE files generated by BC.EXE larger than those generated by
  1191.     BCC.EXE?
  1192.  A. In the default configuration, BC.EXE includes debugging information in
  1193.     the .EXE files that it creates, and BCC.EXE does not. If you don't want
  1194.     to produce this debugging information, you can shut it off in the
  1195.     Integrated Development Environment by selecting Alt-O|B|N.
  1196.  
  1197.  Q. Why do I get "declaration syntax error" messages on dos.h?
  1198.  A. You have set the "ANSI keywords only" option ON. Keep this option OFF
  1199.     when using any keywords specific to Borland C++. See the Borland C++
  1200.     Programmer's Guide for a list of keywords.
  1201.  
  1202.  Q. I get errors when compiling the windows.h header file.  Why?
  1203.  A. Be sure that you have "Borland C++" selected as your keywords option.
  1204.     This option can be toggled under Options | Compiler | Source.
  1205.  
  1206.  Q. I have a working program that dynamically allocates memory
  1207.     using malloc() or calloc() in small data models (tiny, small,
  1208.     and medium). When I compile this program in large data models
  1209.     (compact, large, and huge), my program hangs.
  1210.  A. Make sure that you have #include <alloc.h> in your program.
  1211.  
  1212.  Q. I am linking my own assembly language functions with Borland C++.
  1213.     But the linker reports that all of my functions are undefined.
  1214.  A. See answer above in the "Linker" section.
  1215.  
  1216.  Q. My far pointers "wrap around" when they are incremented over 64K.
  1217.     How do I reference a data object that is greater than 64K?
  1218.  A. Use huge pointers.
  1219.  
  1220.  Q. How do I interface Borland C++ routines to a Turbo Pascal program?
  1221.  A. See the example programs CPASDEMO.PAS and CPASDEMO.C.
  1222.  
  1223.  Q. How do I get Clipper to link with Borland C++?
  1224.  A. If you are having trouble, contact Nantucket Technical Support.
  1225.  
  1226.  Q. I'm trying to build an app based on one of Borland's libraries
  1227.     (ObjectWindows, Turbo Vision, the container classes in the
  1228.     CLASSLIB directory, or the Runtime Library),  and I get
  1229.     linker errors, or it won't run right. What's going wrong?
  1230.  
  1231.  A. You may be using a switch that affects linkage in your files,
  1232.     that was not used when the library itself was compiled, or you
  1233.     need to change the library in question. Here are some examples:
  1234.  
  1235.     - If you use far vtables (-Vf or Options|Compiler|C++|Far
  1236.       virtual tables) to compile a file you developed which
  1237.       includes iostream.h, it won't build correctly until you
  1238.       rebuild the iostream library with the same option.
  1239.  
  1240.     - If you use word alignment (-a or Options|Compiler|Code
  1241.       Generation|Word alignment) in building a Turbo Vision
  1242.       application, you must build the Turbo Vision library from
  1243.       source with the same option.
  1244.  
  1245.     - If you opt to use the templates implementation of the container
  1246.       class library to build ObjectWindows applications, you must
  1247.       rebuild the necessary ObjectWindows libraries from source
  1248.       using the templates implementation of the class library
  1249.       (the BIDxxxx.LIB files.)
  1250.  
  1251.  Q. I got a "bad call to intrinsic function" message when attempting
  1252.     to compile one of my source files. What does this mean?
  1253.  A. This message appeared because you tried to use an intrinsic
  1254.     function in a small model DLL. Either avoid using intrinsic
  1255.     functions in your DLL (see Appendix A of the User's Guide), or
  1256.     turn off the -Oi and -O2 switches (Options|Compiler|Optimizations|
  1257.     inline intrinsic or |Fastest Code).
  1258.  
  1259.  Q: I open up a file in append mode, and append some data to the
  1260.     end of the file.  When I look at the data in an ascii editor, I can't
  1261.     see the appended data.  Why?
  1262.  A: The data is being appended after the End-of-File mark, and the
  1263.     ascii editor is not displaying the data after the EOF mark.  To
  1264.     eliminate the EOF mark:
  1265.     1)  Get the file length with the filelength() function:
  1266.             FILE *file_pointer = fopen( "file.nam","a" );
  1267.             long length = filelength( fileno( file_pointer ));
  1268.     2)  Use the chsize() function to change the file length to the
  1269.         current length-1:
  1270.             chsize( fileno( file_pointer ), (length -1));
  1271.     3)  Then write your appended data to the file.
  1272.  
  1273.  Q: I run my program, allocate some memory, and check the amount of
  1274.     memory available with coreleft().  Then I free some memory and call
  1275.     coreleft() again.  It reports the same number.  Why?
  1276.  A: Coreleft does NOT return the amount of memory available.  It returns
  1277.     the total memory available above the highest block allocated.  It does
  1278.     NOT return any amount of memory available in "holes" below the highest
  1279.     allocated block.
  1280.