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
  -E                            Stop after the preprocessing stage
  -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 warning[,...]              Suppress warnings
  -d                            Debug mode
  -g                            Add debug info to object file
  -h                            Help (this text)
  -j                            Default characters are signed
  -mm model                     Set the memory model
  -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 (6502, 65c02)
  --create-dep name             Create a make dependency file
  --create-full-dep name        Create a full make dependency file
  --data-name seg               Set the name of the DATA segment
  --debug                       Debug mode
  --debug-info                  Add debug info to object file
  --debug-opt name              Debug optimization steps
  --dep-target target           Use this dependency target
  --disable-opt name            Disable an optimization step
  --enable-opt name             Enable an optimization step
  --forget-inc-paths            Forget include search paths
  --help                        Help (this text)
  --include-dir dir             Set an include directory search path
  --list-opt-steps              List all optimizer steps and exit
  --list-warnings               List available warning types for -W
  --local-strings               Emit string literals immediately
  --memory-model model          Set the memory model
  --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. See also #pragma bss-name.


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

--code-name seg

Set the name of the code segment. See also #pragma code-name

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

Set the CPU, the compiler generates code for. You may specify "6502" or "65C02" as the CPU. The default depends on the selected target (see option -t). It is the 6502 CPU for most targets or if no target has been set. Specifying 65C02 will use a few 65C02 instructions when generating code. Don't expect too much from this option: In most cases the difference in size and speed is just 1-2%.

--create-dep name

Tells the compiler to generate a file containing the dependency list for the compiled module in makefile syntax. The output is written to a file with the given name. The output does not include system include files (in angle brackets).

--create-full-dep name

Tells the compiler to generate a file containing the dependency list for the compiled module in makefile syntax. The output is written to a file with the given name. The output does include system include files (in angle brackets).

--data-name seg

Set the name of the data segment. See also #pragma data-name

-d, --debug

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

--dep-target target

When generating a dependency file, don't use the actual output file as the target of the dependency, but the file specified with this option. The option has no effect if neither --create-dep nor --create-full-dep is specified.

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


List the names of warning types available for use with -W.


Emit string literals into the rodata segment as soon as they're encountered in the source (even if you do nothing but get the sizeof those strings). The default is to keep string literals until end of assembly, merge read only literals if possible, and then output the literals into the data or rodata segment that is active at that point. Use of this option prevents merging of duplicate strings, but the options that change the name of one of the data segments will work.

You can also use #pragma local-strings for fine grained control.

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


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). See also #pragma rodata-name

-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 signed-chars 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 the character set that is used for strings and character constants and the default CPU. The CPU setting can be overriden by use of the --cpu option.

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. You can also use #pragma writable-strings to control this option from within the source file.

-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 static-locals 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). See also the --register-vars command line option, and the discussion of register variables below.

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 name[,name]

This option allows to control warnings generated by the compiler. It is followed by a comma separated list of warnings that should be enabled or disabled. To disable a warning, its name is prefixed by a minus sign. If no such prefix exists, or the name is prefixed by a plus sign, the warning is enabled.

The following warning names are currently recognized:


Warn if the result of a comparison is constant.


Treat all warnings as errors.


Warn about statements that don't have an effect.


Warn when passing structs by value.


Warn about known #pragmas.


Warn about unused labels.


Warn about unused function parameters.


Warn about unused variables.

The full list of available warning names may be retrieved by using the option --list-warnings.

You may also use #pragma warn to control this setting for smaller pieces of code from within your code.

Next Previous Contents