Re: [cc65] Problem with .define (ca65)

Date view Thread view Subject view

From: Ullrich von Bassewitz (uz_at_musoftware.de)
Date: 2002-07-15 23:37:16


On Mon, Jul 15, 2002 at 09:55:11PM +0200, Stephan Lesch wrote:
> Can anyone find a mistake in the source below? It should
> result in a file with a 1 byte if 'yiff' is defined, and
> a 2 byte otherwise. It works if I define the symbol on the
> command line, but not if it's defined in the source.
> Are the .define and the .ifdef syntactically correct?

They are syntactically correct, but not semantically:-)

.define is not used to define symbols, it is used to define very, very low
level macros. What you did, was creating a macro yiff that expands to nothing.
This is the reason why you got an error at the line with the .ifdef (yiff
expanded to nothing, so the .ifdef was without an argument).

To define symbols, use the equal sign (=). Your code may then look like this:

	foo	= 3

	.ifdef 	foo
		.byte	foo
	.else
		.byte	0
	.endif

While .define has some very rare uses, it is better not to use it at all. Some
time ago, a company paid me for adding some features to ca65, so they could
replace their own assembler with ca65. One of the requests was that it must be
possible to translate most programs written for that older assembler with
ca65. Instead of making ca65 compatible to this old assembler, I decided to
add some meta features that change the way, ca65 works. .define is one of
these features. It defines very low level macros. These macros work on the
token level and will completely ignore scoping. If, for example, you don't
like using '=' to assign values to symbols, you may use

	.define	equ	=

This will replace all 'equ' tokens in the input by '=', so you can write

	foo   	equ	3

The assembler documentation has some more examples. But as I said above,
.define is rather dangerous, so don't use it if you don't have to.

Regards


	Uz


-- 
Ullrich von Bassewitz                                  uz_at_musoftware.de
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo_at_musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.


Date view Thread view Subject view

This archive was generated by hypermail 2.1.3 : 2002-07-15 23:39:05 CEST