【正文】
your program is portable to any 16bit or 32bit Microsoft Windows platform or to the Macintosh. Compilers normally align structures based on the target machine architecture。 the Macintosh allows for only 16. Because of the differences between the two platforms, porting a Windowsbased application to the Macintosh can be monumental task without powerful tools. Windows has always run on Intel x86 processors (until Windows NT), and the Macintosh has run on Motorola 680x0 processors (of course, the PowerPCbased Macintosh is now available as well). Differences between the processor families include addressing and byte ordering, in addition to the more expected differences like opcodes, instruction sets, and the name and number of registers. The Intel 8086 processor, from which subsequent 80x86 processors are descended, used 16bit addresses, which unfortunately allowed only 65,536 bytes of memory to be addressed. To allow the use of more memory, Intel implemented a segmented memory architecture to address one megabyte (2^20 bytes) of memory that used an unsigned 16bit segment register and an unsigned 16bit offset. This original Intel scheme has been extended to allow muc h larger amounts of memory to be addressed, but most existing Intelbased programming relies on separating code and data into 64K segments. Although all Intel x86 processors since the 80386 have used 32bit addressing, for patibility reasons Microsoft Windows is actually a 16bit application, and all Microsoft Windowsbased applications had to be written as 16bit applications. That meant, for example, that most pointers and handles were 16 bits wide. With the advent of Microsoft Windows NT, which is a true 32bit operating system, all native applications are 32bit applications, which means that pointers and handles are 32 bits wide. Because Windows NT uses linear addressing, programs can share up to 4 gigabytes of memory. In contrast, the Motorola 68000 and PowerPC processor have always provided the ability to address a flat 32bit memory space. In theory, a flat memory space of this kind simplifies memory addressing. In practice, because 4byte addresses are too large to use all the time, Macintosh code is generally divided into segments no larger than 32K. Microsoft Windows and Windows NT run only on socalled littleendian machines—processors that place the least significant byte first and the most significant byte last. In contrast, the Motorola 680x0 and PowerPC (a socalled bigendian architecture) place the most significant byte first, followed by the next most significant byte, and so on, with the least significant byte last. Compilers normally handle all details of byte ordering for your application program. Nevertheless, wellwritten portable code should never depend on the order of bytes. Microsoft Windows and the Macintosh present quite different user interfaces in many key areas, including menus, filenames, and multipledocument interface (MDI) applications. Only one menu bar exists on the Macintosh, and it is always in the same place, regardless of the number or arrangement of windows on the screen. The active window contains the menu, which dynamically changes as necessary when different windows are made active. Windows, on the other hand, gives each toplevel window its own menu. In addition, under MDI, each child window can also have its own menu. MDI is discussed in greater detail below. Macintosh applications generally have an Apple menu (the leftmost menu) that contains all the installed Desk Accessories and usually contains an About entry for the application. Under System 7, the extreme right side of the Macintosh menu contains an icon for Apple39。直到不久之前,希望開發(fā)多平臺(tái)任務(wù)的開發(fā)者們,只有很少的幾種選擇: ? 根據(jù)各個(gè)平臺(tái)的不同的應(yīng)用程序接口,為每個(gè)平臺(tái)準(zhǔn)備一份單獨(dú)的代碼。開發(fā)人員可以通過使用微軟和第三方的工具,把他們現(xiàn)存的針對(duì) Windows API 寫的代碼,對(duì)以上列舉的各種平臺(tái)重新編譯。一般情況下,對(duì) Macintosh 應(yīng)用程序的開發(fā),需要和 Windows 不同的代碼 庫(kù),這些都增加了維護(hù)和升級(jí)的復(fù)雜度。它還提供了一個(gè)轉(zhuǎn)換庫(kù)來輔助 Windows 程序在Macintosh 上運(yùn)行。你的源代碼在Windows NT 或 Windows 95 上面編寫,編譯,連接。 現(xiàn)在, Apple 公司有兩個(gè)不同的 Macintosh 結(jié)構(gòu)來競(jìng)爭(zhēng),可轉(zhuǎn)換性尤其重要。 3. 把你獨(dú)特的 Windows 應(yīng)用程序分割,從熟悉的執(zhí)行方式到 Macintosh。使用 MFC 編寫的代碼對(duì) Macintosh 有很高的可轉(zhuǎn)換性。已經(jīng)使用過這些工具進(jìn)行再編譯 Win32 資源的開發(fā)人員,對(duì)這過程的簡(jiǎn)單感到驚訝,因?yàn)檫@些平臺(tái)上的操作系統(tǒng)是各自獨(dú)立的,它們的工具也是獨(dú)立的,但是完成一個(gè)轉(zhuǎn)換確只需要很少的工作量。 一般來說你會(huì)發(fā)現(xiàn) MFC 程序可轉(zhuǎn)換性比 Win32 程序好,這是因?yàn)閼?yīng)用程序 框架的一個(gè)內(nèi)在優(yōu)勢(shì)是對(duì)基本操作系統(tǒng)進(jìn)行了一定程度的提煉,這種提煉類似于為你提供了一種安全保證。 Visual C++ 系統(tǒng)提供了一個(gè)很好地 MFC 指南(Scribble),然后,購(gòu)買 MFC Migration Kit(可以網(wǎng)上付費(fèi),自己郵寄到微軟),它將幫助你把 C 程序移植轉(zhuǎn)換成為 MFC 和 C++。例如, int 在 Win16 和 Win32 上分別是 2 個(gè)字節(jié)和 4 個(gè)字節(jié),無論如何,避免代碼依賴于數(shù)據(jù)類型的大小。 分解數(shù)據(jù)類型以提取單獨(dú)的字節(jié)或比特,會(huì)在從 Windows 到 Macintosh 的轉(zhuǎn)換時(shí)出問題,除非你在寫代碼時(shí)候小心,不假定任何類型分解。然而,如果你想轉(zhuǎn)換代碼,要避免這種誘惑。 用 c 語(yǔ)言編寫所有的程序,然后,如果你必須用匯編碼重寫,確保把兩種執(zhí)行程序都保存,利用條件編譯,并且保持兩 種程序的更新。 Microsoft Visual C++為 ANSI C 提供了一些語(yǔ)言細(xì)節(jié)的補(bǔ)充,例如 4 字符常數(shù)和單行的注釋。排列錯(cuò)誤可能導(dǎo)致執(zhí)行期錯(cuò)誤,或者可能悄悄地和顯著的影響你的程序。 為 Win32編寫的代碼可以在任何 Windows版本下運(yùn)行,有轉(zhuǎn)換庫(kù)時(shí)候還可以在 Macintosh下運(yùn)行。 Win16 和 Win32 的主要區(qū)別是尋址長(zhǎng)度,意思是現(xiàn)在 32 位的指針對(duì)于或遠(yuǎn)或近的關(guān)鍵詞不再支持了,也意味著分段存儲(chǔ)的代碼在 Win32 下會(huì)不能工作。最后用一個(gè)可轉(zhuǎn)換的版本代替所有的子函數(shù)。伴隨這些區(qū)別出現(xiàn)的轉(zhuǎn)換問題會(huì)在“從 Win32 到 Macintosh 的轉(zhuǎn)換”一節(jié)中討論。 ? Windows 使用子窗口的概念, Macintosh 不使用子窗口。Macintosh 只允許 16 位的操作。 Intel 8086 處理器 , 以及隨后衍生的 80x86 系列處理器使用 16bit 地址, 只能支持 65,536 bytes 的存儲(chǔ)器尋址。這就是說絕大多數(shù)的指針和句柄是 16 bits 長(zhǎng)。實(shí)踐中,因?yàn)?4byte 尋址由于太大不會(huì)一直使用, Macintosh 代碼一般分到不大于 32K 的段中存儲(chǔ)?!盎顒?dòng)窗口” 包含菜單,這個(gè)菜單會(huì)隨著活動(dòng)窗口的改變而動(dòng)態(tài)的變化。在 System 7 中 , Macintosh 菜單的最右邊包含了一個(gè) Apple 的幫助圖標(biāo),還有一個(gè)負(fù)責(zé)應(yīng)用程序之間切換的菜單。 文件名和路徑名是 Windows 和 Macintosh 之間最大的區(qū)別之一,而且也許是最難出的。 MDI 程序的一個(gè)特點(diǎn)是子窗口最小化后,會(huì)在 MDI框架內(nèi)部產(chǎn)生一個(gè)圖標(biāo)。 最終你能夠繼續(xù)作你最了解的工