Pascal Understands C
Volume Number: 9
Issue Number: 12
Column Tag: Pascal workshop
Pascal Programmer’s Guide
to Understanding ‘C’
Teach yourself to read another language - Part I
By Ken Gladstone, MacTech Magazine Technical Editor
Most of the articles that we receive here at MacTech Magazine use source code
that is written in C. We have had a number of readers request that we either publish
more articles that use Pascal, or that we provide Pascal translations of our source code
listings. Since we can’t force authors to use Pascal, and since we really don’t want to
translate every piece of C code that we publish, our reply has always been “You should
be reading the articles to learn the programming concepts, and it shouldn’t matter
what language we use in the listings. (Or you should submit more Pascal-based
articles!)” Well, we have had several readers respond saying that this would be fine,
except that they are unable to read C - a valid complaint.
With this article, I aim to remove that as a valid complaint. This article is
designed to teach Pascal programmers how to understand C code listings. Although
since my Pascal is a little rusty and I now program primarily a C, perhaps I should
have written an article entitled “The ‘C’ Programmer’s Guide to Remembering
Pascal!” This article is in no way intended to be a complete C reference, but is simply
intended to help you Pascal programmers understand the C listings that you see in our
magazine or elsewhere.
Let me provide a little information on the history of C and some of its
incarnations. The original Bible for C programmers is a book called “The C
Programming Language” by Brian Kernighan and Dennis Ritchie, published by
Prentice-Hall. The book is often refered to as “Kernighan and Ritchie,” or simply
“K&R.” If after reading this article you want to see the true original C reference, I
suggest you pick up a copy of K&R. Since that time, the C language has been expanded
and standardized, resulting in ANSI C. In addition to supporting ANSI C, most current
compilers have their own extentions to the language. At times, I will refer to Mac
specific aspects of the C language. So, let’s begin:
COMMENTS
We’ll start with comments because they are easy (and also because K&R start
with them in the reference section of their book).
/* 1 */
/* A forward slash followed by a star signifies the beginning of a C
comment. Comments can span multiple lines, and are ended by a star
and another slash */
There is a second form of comment that is not in K&R C, but that is supported in
many C compilers, including MPW and Think C. Two forward slashes signify a
comment that continues until the end of the line. Here are three uses of that style
comment:
// 2
// A one line comment
LineOfCode(ThisIs); // Comment at end of a line of code
// LetsCommentOut += ThisLineOfCode;
IDENTIFIERS
Both C and Pascal have similar rules about naming identifiers: you can use