Next Previous Contents

2. Usage

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

2.1 Command line option overview

The compiler may be called as follows:

Usage: cc65 [options] file
Short options:
  -Cl                   Make local variables static
  -Dsym[=defn]          Define a symbol
  -I dir                Set an include directory search path
  -O                    Optimize code
  -Oi                   Optimize code, inline more code
  -Or                   Enable register variables
  -Os                   Inline some known functions
  -T                    Include source as comment
  -V                    Print the compiler version number
  -W                    Suppress warnings
  -d                    Debug mode
  -g                    Add debug info to object file
  -h                    Help (this text)
  -j                    Default characters are signed
  -o name               Name the output file
  -r                    Enable register variables
  -t sys                Set the target system
  -v                    Increase verbosity

Long options:
  --add-source          Include source as comment
  --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
  --forget-inc-paths    Forget include search paths
  --help                Help (this text)
  --include-dir dir     Set an include directory search path
  --register-space b    Set space available for register variables
  --register-vars       Enable register variables
  --rodata-name seg     Set the name of the RODATA segment
  --signed-chars        Default characters are signed
  --standard std        Language standard (c89, c99, cc65)
  --static-locals       Make local variables static
  --target sys          Set the target system
  --verbose             Increase verbosity
  --version             Print the compiler version number
  --writable-strings    Make string literals writable

2.2 Command line options in detail

Here is a description of all the command line options:

--bss-name seg

Set the name of the bss segment.


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 and optimization phases. 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 -O --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.


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".


Forget the builtin include paths. This is most useful when building customized C or runtime libraries, in which case the standard header files should be ignored.

-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.

-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".

-r, --register-vars

-r 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. Since register variables are of limited use without the optimizer, there is also a combined switch: -Or will enable both, the optimizer and register variables.

For more information about register variables see register variables.

The compiler setting can also be changed within the source file by using #pragma regvars.


This option takes a numeric parameter and is used to specify, how much zero page register space is available. Please note that just giving this option will not increase or decrease by itself, it will just tell the compiler about the available space. You will have to allocate that space yourself using an assembler module with the necessary allocations, and a linker configuration that matches the assembler module. The default value for this option is 6 (bytes).

If you don't know what all this means, please don't use this option.

--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.

--standard std

This option allows to set the language standard supported. The argument is one of


This disables anything that is illegal in C89/C90. Among those things are // comments and the non-standard keywords without underscores. Please note that cc65 is not a fully C89 compliant compiler despite this option. A few more things (like floats) are missing.


This enables a few features from the C99 standard. With this option, // comments are allowed. It will also cause warnings and even errors in a few situations that are allowed with --standard c89. For example, a call to a function without a prototype is an error in this mode.


This is the default mode. It is like c99 mode, but additional features are enabled. Among these are "void data", non-standard keywords without the underlines, unnamed function parameters and the requirement for main() to return an int.

Please note that the compiler does not support the C99 standard and never will. c99 mode is actually c89 mode with a few selected C99 extensions.

-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.


Make string literals writable by placing them into the data segment instead of the rodata segment.

-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 that 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, -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 -O --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.


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