Re: [cc65] Print heart character on C64?

From: Ullrich von Bassewitz <uz1musoftware.de>
Date: 2004-12-01 12:14:32
On Wed, Dec 01, 2004 at 10:32:53AM +0100, Spiro Trikaliotis wrote:
> In this case, what is translated, and what not? Above, you told that
> CC65 translates all string and character literals. From this, I assume
> 'H', 'e', 'l', 'o' are translated. Correct?

Yes.

> But 0x73, 0x00 are no character literals, so, they are not translated.
> Correct?

Yes.

> Now, should
>
>  sprintf(buffer, "M-W%c%c%c", 0x01, 0x02, 0x03);
>
> show the expected behaviour? Or do I have to use the char array, as
> above?

The above works, but it's quite some overhead, because the string is assembled
at runtime, and sprintf is not exactly a lightweight function. If you know the
char values in advance, the char array approach is better for both, size and
speed of the final program. If you don't know the values of the additional
characters in advance, I would suggest something like

	char cmd[7] = "M-W";

	...
	char[4] = c1;
        char[5] = c2;
        char[6] = c3;

> Is this behaviour guaranteed from the C standard?

Which behaviour do you mean? If you mean character set translation, then the
answer is that the standard allows it (see ISO/IEC 9899:1999 (E), "5.2.1
Character sets"). The standard does not *require* character set translation,
and what exactly happens when it is done is implementation defined. It would
be possible not to translate any numeric escape sequences, but in my eyes this
would be more confusing than as it is now. Currently anything between "" and
'' is translated, which is quite straightforward.

I was thinking about abusing wide strings (with the 'L' modifier) for strings
that will not get translated. This would not be fully standards compliant, but
on the other side not much harm is done, because wide character strings are
always implementation defined and as a consequence are never portable.
However, this feature is currently not available, so you have to use one of
the other methods described in my earlier mail.

Regards


	Uz


-- 
Ullrich von Bassewitz                                  uz@musoftware.de
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Wed Dec 1 12:14:42 2004

This archive was generated by hypermail 2.1.8 : 2004-12-01 12:14:53 CET