[Coco] RE: Learning MW C (REALLY!)

Ries, Rich [S&FS] Rich.Ries at Honeywell.com
Tue Aug 15 12:42:20 EDT 2006


-----Original Message-----

>Message: 1

>Date: Tue, 15 Aug 2006 01:17:38 -0500

>From: "George's Coco Address" <yahoo at dvdplayersonly.com>

>Subject: Re: [Color Computer] [coco] Learning MW C (REALLY!)

>To: "CoCoList for Color Computer Enthusiasts" <coco at maltedmedia.com>

>Message-ID: <008401c6c032$85e8c480$ecb8b1d8 at heart>

>Content-Type: text/plain; format=flowed; charset="iso-8859-1";

> reply-type=original

>

>The C Programming Language, by Kernighan and Ritchie

>

>This book is readily available and from what I've read, it's a good

source on the K&R C.

>I also found what seems to be a good suppliment for this book available

beginning here:

>http://c-faq.com/~scs/cclass/krnotes/index.html

>

>This, I think, would be a great start once I learn how to use the OS-9

software that is needed to

>compile whatever it is I might try.

>

>I would expect that whatever I can learn in the book and the online

suppliment would work with the OS-9

>compiler but, correct me if I am wrong.

>

>The book that came with the C-Compiler for OS-9 claims an almost

perfect implementation of the K&R C.

>There are five instances mentioned in this book whick are exceptions.

The OS9 book also mentions the

>K&R book as a reference. pp 1-2

>

>Tomorrow, I'm going to begin reading this OS-9 book and try to

understand the process of compiling the

>simple "Hello World" thing before I actually begin trying to compile

the simple "Hello World" thing.

>That's where I went wrong several years ago. I didn't start with the

basics.

>

>George

>



Hello, George!
This was my experience; yours may vary!
I had trouble getting my head around the uWare C, and most of the books
I had were ANSI-based, which caused more grief. (I didn't get K&R's book
until much later...)

All that just to say, if you need help, give me a holler! I make a
living using a "kinda-ANSI/kinda K&R" C for microcontrollers, so I may
be able to help you out. My CoCo system is still packed away, so
questions like "what bit should I twiddle?" will result in "Beats me!"
answers. :D

One Very Important Thing in C is to keep the braces lined up, and
matched. For this alone I would develop my C on a PC (ugh!) machine with
a modern editor that can show the matching brace, parenthesis, or
bracket marks. Then I'd download it to the CoCo.

My other problem was remembering if | was logical or bitwise OR. The
same for && and ^. I finally wrote a header file that I can #include in
my files. (Drives everyone else crazy, but...) Here it is:

[code]
/* Logical operators */
#define L_AND &&
#define L_OR ||
#define L_NOT !

/* Bitwise operators */
#define b_and &
#define b_or |
#define b_xor ^
#define b_not ~

/*.
* 'Cause most C's don't have a "0b10100101" construct,
* and it's really handy with micros.
*/

#define b(b7,b6,b5,b4,b3,b2,b1,b0)
((b7*128+b6*64+b5*32+b4*16+b3*8+b2*4+b1*2+b0))

/*
* Bit operations -
* Note there is no limit to how many bits are in a byte.
*
* tobit(20000) will work....
*
*/
#define tobit(x) (1 << ((x)))

#define setbit(bitno,byt) ( (byt) |= (tobit(bitno)))
#define clrbit(bitno,byt) ( (byt) &= ~(tobit(bitno)))
#define isset(bitno,byt) ( (byt) & (tobit(bitno)))
#define isclr(bitno,byt) (!((byt) & (tobit(bitno))))
[/code]

You'll notice the logical operators (L_NOT, etc.) were borrowed from
BASIC09, and the bitwise operators (b_and) followed logically from them.

Good luck in your projects!

--Rich





More information about the Coco mailing list