[cc65] c question

From: Chiron Bramberger <chiron1bramberger.com>
Date: 2010-05-27 08:32:47
I hope nobody minds if I ask what's probably just a simple c question.

I'm eventually going to write a struct so I can clearly read/write to  
the VIA chip's registers on the PET using a nicely put together  
interface (like the SID one in cc65 for the C64) but I was hoping  
someone might not mind helping me understanding something first.

In the cc65 faq:

typedef unsigned char byte;
     typedef unsigned word;
     byte B;
     word W;

     *(byte*) 0xD800 = 0x12;    /* Store a byte to address $D800 */
     *(word*) 0xC000 = 0x1234;  /* Store a word to address $C000 */
     B = *(byte*) 0xD800;       /* Read a byte from address $D800 */
     W = *(word*) 0xC000;       /* Read a word from address $C000 */

I'm sorry, but I looked this up in my old C textbook, and even though  
there are similar examples, I can't find an answer to this question  
anywhere.

What does the asterisk * in (byte*) mean? I know *p is a pointer, and  
I know &q would be an address, but what does it mean when the * is  
after something?

In my textbook there's a second, similar example:

typedef unsigned char BYTE;
BYTE *p;
p = (BYTE *) 0x1000; /* p contains address 0x1000 */

I know in this case, the *p is the pointer of type BYTE, and I know  
that (BYTE *) is a cast (right?), and (in the first example) I know  
that the * on the outside to the left makes the enclosing brackets  
resolve to a pointer,  but what is the * for, and why is it inside  
the brackets and on the right?  I know 0x1000 is a literal verbatim  
and explicitly stated memory address, and I know that the line means  
p (which is a pointer) should now equal a pointer to the specific  
address 0x1000, which holds a value of the type BYTE.

But what does the * mean (on_the_right*)? I really want to truly  
understand this and not just how to "make it go". I want to get it.

TIA!
-Chiron


----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Thu May 27 08:32:59 2010

This archive was generated by hypermail 2.1.8 : 2010-05-27 08:33:03 CEST