Next Previous Contents

2. Usage

The compiler translates C files into files containing assembler code that may be translated by the ca65 macroassembler (for more information about the assembler, have a look at ca65.txt).

2.1 Command line option overview

The compiler may be called as follows:

---------------------------------------------------------------------------
Usage: cc65 [options] file
Short options:

Long options:
  --add-source          Include source as comment
  --ansi                Strict ANSI mode
  --bss-name seg        Set the name of the BSS segment
  --check-stack         Generate stack overflow checks
  --code-name seg       Set the name of the CODE segment
  --codesize x          Accept larger code by factor x
  --cpu type            Set cpu type
  --create-dep          Create a make dependency file
  --data-name seg       Set the name of the DATA segment
  --debug               Debug mode
  --debug-info          Add debug info to object file
  --help                Help (this text)
  --include-dir dir     Set an include directory search path
  --rodata-name seg     Set the name of the RODATA segment
  --signed-chars        Default characters are signed
  --static-locals       Make local variables static
  --target sys          Set the target system
  --verbose             Increase verbosity
  --version             Print the compiler version number
---------------------------------------------------------------------------

2.2 Command line options in detail

Here is a description of all the command line options:

-A, --ansi

This option disables any compiler exensions. Have a look at section 5 for a discussion of compiler extensions. In addition, the macro __STRICT_ANSI__ is defined, when using one of these options.

--bss-name seg

Set the name of the bss segment.

--check-stack

Tells the compiler to generate code that checks for stack overflows. See #pragma checkstack for an explanation of this feature.

--code-name seg

Set the name of the code segment.

--codesize x

This options allows finer control about speed vs. size decisions in the code generation phase. It gives the allowed size increase factor (in percent). The default is 100 when not using -Oi and 200 when using -Oi (-Oi is the same as --codesize 200).

--cpu CPU

A new, still experimental option. You may specify "6502" or "65C02" as the CPU. 6502 is the default, so this will not change anything. Specifying 65C02 will use a few 65C02 instructions when generating code. Don't expect too much from this option: It is still new (and may have bugs), and the additional instructions for the 65C02 are not that overwhelming.

--create-dep

Tells the compiler to generate a file containing the dependency list for the compiled module in makefile syntax. The file is named as the C input file with the extension replaced by .u.

-d, --debug

Enables debug mode, something that should not be needed for mere mortals:-)

-D sym[=definition]

Define a macro on the command line. If no definition is given, the macro is defined to the value "1".

-g, --debug-info

This will cause the compiler to insert a .DEBUGINFO command into the generated assembler code. This will cause the assembler to include all symbols in a special section in the object file.

-h, --help

Print the short option summary shown above.

--rodata-name seg

Set the name of the rodata segment (the segment used for readonly data).

-j, --signed-chars

Using this option, you can make the default characters signed. Since the 6502 has no provisions for sign extending characters (which is needed on almost any load operation), this will make the code larger and slower. A better way is to declare characters explicitly as "signed" if needed. You can also use #pragma signedchars for better control of this option.

-t target, --target target

This option is used to set the target system. The target system determines things like the character set that is used for strings and character constants. The following target systems are supported:

-v, --verbose

Using this option, the compiler will be somewhat more verbose if errors or warnings are encountered.

-Cl, --static-locals

Use static storage for local variables instead of storage on the stack. Since the stack is emulated in software, this gives shorter and usually faster code, but the code is no longer reentrant. The difference between -Cl and declaring local variables as static yourself is, that initializer code is executed each time, the function is entered. So when using

        void f (void)
        {
            unsigned a = 1;
            ...
        }
  

the variable a will always have the value 1 when entering the function and using -Cl, while in

        void f (void)
        {
            static unsigned a = 1;
            ....
        }
  

the variable a will have the value 1 only the first time, the function is entered, and will keep the old value from one call of the function to the next.

You may also use #pragma staticlocals to change this setting in your sources.

-I dir, --include-dir dir

Set a directory where the compiler searches for include files. You may use this option multiple times to add more than one directory to the search list.

-o name

Specify the name of the output file. If you don't specify a name, the name of the C input file is used, with the extension replaced by ".s".

-O, -Oi, -Or, -Os

Enable an optimizer run over the produced code.

Using -Oi, the code generator will inline some code where otherwise a runtime functions would have been called, even if the generated code is larger. This will not only remove the overhead for a function call, but will make the code visible for the optimizer. -Oi is an alias for --codesize 200.

-Or will make the compiler honor the register keyword. Local variables may be placed in registers (which are actually zero page locations). There is some overhead involved with register variables, since the old contents of the registers must be saved and restored. In addition, the current implementation does not make good use of register variables, so using -Or may make your program even slower and larger. Use with care!

Using -Os will force the compiler to inline some known functions from the C library like strlen. Note: This has two consequences:

It is possible to concatenate the modifiers for -O. For example, to enable register variables and inlining of known functions, you may use -Ors.

-T, --add-source

This include the source code as comments in the generated code. This is normally not needed.

-V, --version

Print the version number of the compiler. When submitting a bug report, please include the operating system you're using, and the compiler version.

-W

This option will suppress any warnings generated by the compiler. Since any source file may be written in a manner that it will not produce compiler warnings, using this option is usually not a good idea.


Next Previous Contents