Mac OS 7-9 - C programming
Asked Answered
C

2

7

I'm curious how many C features that depend on standard Unix features work on Mac OS System 7 through OS 9. I don't have any development experience with the platform, but I know that there is no command line nor anywhere for the standard streams to work. Without a command line are there any command-line arguments? What about environment variables?

I did try looking for a classic Mac OS programming guide, but they're surprisingly hard to find.

Cindelyn answered 19/11, 2012 at 22:57 Comment(1)
There are a bunch of Classic Mac OS programmers active on the 68kMLA forums. I believe they will be able to help you obtain MPW and other tools.Victoria
R
14

First of all, there are no C features that are dependent on Unix. C runs just fine on Windows, and it runs just fine on 8-bit microcontrollers.

As for classic Mac OS, there were two primary programming environments: Metrowerks CodeWarrior and Apple's MPW.

  1. CodeWarrior came with a library called SIOUX which opened up a window and provided simple I/O. Any printf statements would print to this window. There's no piping or sockets, but that's not part of the C standard anyway (pipes are a part of POSIX). Using SIOUX, you could port a simple program to Mac OS as long as it stuck to portable C.

  2. Apple's MPW was the other option. MPW provided a command line, a bunch of command-line programs (compilers for C, C++, Pascal, assembly), and dialog box "shells" for generating command line arguments to the programs. You could even use pipes, set environment variables, et cetera.

    There were, however, some major differences in functionality between Unix and MPW. MPW had a great interface, but you could not run two command line programs simultaneously, not even in the very trivial case where one is suspended to run the other. This meant that the "make" program couldn't run the compiler. Instead, "make" generated a shell script which would run the compiler. You'd typically have some kind of keyboard shortcut that would run "make" and then run the resulting output as a shell script.

    Now, this seems to imply that pipes wouldn't work, but I think pipes were just syntactic sugar for working with temporary files.

    Xcode has no MPW heritage, as far as I know. Xcode derives from Project Builder which was developed at NeXT, and NeXT was always Unix. Apple ported some of the old MPW command-line tools to OS X, but not many. The big one is Rez (and DeRez). Since they're shipped with the latest Xcode, I guess somebody is probably still using them. The Rez headers are still around, to get a blast from the past check out:

    find /System/Library/Frameworks -name '*.r'
    

It seems like Apple has really scrubbed their development website of anything older than 10.6, which is a bit of a shame. Not too long ago you could still find the old pre-Carbon documentation, including all of the "Inside Macintosh" series on Apple's website. You also used to be able to get MPW from Apple's FTP site (it was free), and I still have the downloads, but I don't know if you can still download it.

Mind you, you'll need 10.4 (or earlier) and a PowerPC computer before you can even consider playing around with this, unless you've somehow managed to get Sheep Shaver working.

Funny tidbit, there were some funny error messages that MPW's C compiler could produce.

a typedef name was a complete surprise to me at this point in your program

You can't modify a constant, float upstream, win an argument with the IRS, or satisfy this compiler

...And the lord said, 'lo, there shall only be case or default labels inside a switch statement'

type in (cast) must be scalar; ANSI 3.3.4; page 39, lines 10-11 (I know you don't care, I'm just trying to annoy you)

Call me paranoid but finding '/*' inside this comment makes me suspicious

Symbol table full - fatal heap error; please go buy a RAM upgrade from your local Apple dealer

Too many errors on one line (make fewer)

This label is the target of a goto from outside of the block containing this label AND this block has an automatic variable with an initializer AND your window wasn't wide enough to read this whole error message

we already did this function
Ridgway answered 19/11, 2012 at 23:25 Comment(3)
"you could port a simple program to OS X" - no, it wasn't called OS X before release 10 (X)Blythe
@asveikau: Actually, it's true -- CodeWarrior also ran on OS X. But that was a typo.Ridgway
"C runs just fine on Windows" - I had a good laugh at this :DPhonemic
F
4

THINK C/Symantec C also had a standard I/O window that made porting command line programs relatively easy. Program arguments were entered via a dialog.

But far and away the nicest way to do it was with MPW - the Macintosh Programmer's Workshop. It was a very nice command line environment for the MacOS, great editor, scriptable, various "tools" and lots of helpful GUI aspects built in (so it was genuinely Mac-like).

For many years this could be freely downloaded from Apple's developer website. Looks like the link might be gone now, but I'm sure a copy could be found online with a bit of searching. (Try searching for MPW-GM.img.bin or mpw-gm_images.)

Flashy answered 20/11, 2012 at 0:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.