1.9 CodeWarrior Tips and Tricks

The following sections explain how to perform a few tasks that are not readily apparent from the Metrowerks CodeWarrior manuals.

1.9.1 Creating an Alias to an Internal Symbol

Both the Watcom and CodeWarrior linkers allow you to create aliases to internal symbols. When you export the alias, the exported symbol becomes an alias for the internal symbol. Usually you need to create an alias only when you are using the __stdcall calling convention on a function prototype:

  void __stdcall Foo (void)
  

The internal symbol name, and thus the default export name, for this routine would be _Foo@0 under Watcom or Foo%0 under CodeWarrior. The compiler does this because other applications consuming this symbol need to know not to clean up the parameters they push to these functions, because the functions already clean them up before returning to the caller. The name decoration is a clue to the linker that the __stdcall calling convention was used on the exported symbol.

In some circumstances, you might need to dynamically import such routines at runtime. In these cases, where you have inside knowledge about the calling convention of the routines you are importing, you need not export them in decorated format, because it makes it more difficult to import the symbol correctly and in a portable manner. For these circumstances, Watcom allows you to rename the symbol and to export it undecorated with the following types of commands:

  ALIAS Foo=’_Foo@0’
  EXPORT Foo
  

CodeWarrior allows you to do this in one step:

  EXPORT Foo=Foo%0
  

In the CodeWarrior command, be careful not to enclose either symbol in single quotes. Watcom required single quotes around the second symbol because the @ sign has special meaning to the linker. Using single quotes in this manner in the CodeWarrior command generates the following error:

   "Undefined symbol: ’Foo%0’ in export list"
  

CodeWarrior also allows you to specify a prefix while doing this in an export response file. For example:

  #-----------------
  # test.def
  
  EXPORT @test.exp
  
  #------------------
  # test.exp
  
  (TEST),
  Foo=Foo%0
  

These commands generate the exported symbol: TEST@Foo.

1.9.2 Configuring the Correct Data Type for wchar_t

Metrowerks CodeWarrior supports the following command line option:

   { -wchar_t on | off }
  

This option enables or disables a compiler intrinsic type for wchar_t.

  • When set to Off, the CodeWarrior header files define wchar_t to unsigned short.

  • When set to On, the compiler treats wchar_t as any other native type.

Although its size is still equal to an unsigned short, the compiler intrinsic type is not directly compatible with unsigned short. In other words, you can't simply pass a pointer to an unsigned short to any function that takes a pointer to a wchar_t. The compiler issues warnings about type incompatibilities. The type that you should use in these functions should be wchar_t, because that will be equivalent to unsigned short when the intrinsic is disabled, and it is wchar_t when it is enabled. If you are using the wide character functions in wchar.h, you should explicitly enable the wchar_t option.

1.9.3 Using the IDE CodeWarrior Debugger with a Command Line Project

You can use the CodeWarrior debugger even if you don't have an IDE project. You need to have CodeWarrior 7 installed, with the Novell Add-on (PDK) 4.0.

  1. From your command line project, generate a symbolic debugging file that uses the code view format. It should have the file extension of .ncv (that's what the IDE calls them). Also, make sure your NLM is compiled with debug information in it.

  2. Make sure your debugging environment through the IDE is set up correctly and working. For more information, see Targeting the NetWare Operating System PDK 4.0 from Metrowerks.

  3. Open the CodeWarrior IDE, click File > Open, then browse to the .ncv file mentioned in Step 1.

  4. Open the .ncv file.

    Opening an .ncv file starts a debugging session if everything else is set up correctly.