【正文】
zes on different processors. For example, an int is two bytes in Win16 and four bytes in Win32. At all costs, avoid code that relies on the size of a type. Use sizeof() instead. To determine the offset of a field in a structure, use the offsetof() macro. Don39。 CrossDevelopment Edition for Macintosh (Visual C++ for Mac?) provides a set of Windows NT– or Windows 95–hosted tools for repiling your Windows code for the Motorola 680x0 and PowerPC processors, and a portability library that implements Windows on the Macintosh. This allows you to develop GUI applications with a single source code base (written to the Win32174。外文文獻(xiàn)翻譯 原文 : From one code base to many platforms using Visual C++ Multipleplatform development is a hot issue today. Developers want to be able to support diverse platforms such as the Microsoft174。ll find that it will e up on other platforms easily as well. Microsoft Visual C++174。t make assumptions about the sizes of types, the state of the machine at any time, byte ordering, or alignment. Don39。 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ā)人員可以通過使用微軟和第三方的工具,把他們現(xiàn)存的針對 Windows API 寫的代碼,對以上列舉的各種平臺重新編譯。它還提供了一個轉(zhuǎn)換庫來輔助 Windows 程序在Macintosh 上運(yùn)行。 現(xiàn)在, Apple 公司有兩個不同的 Macintosh 結(jié)構(gòu)來競爭,可轉(zhuǎn)換性尤其重要。使用 MFC 編寫的代碼對 Macintosh 有很高的可轉(zhuǎn)換性。 一般來說你會發(fā)現(xiàn) MFC 程序可轉(zhuǎn)換性比 Win32 程序好,這是因?yàn)閼?yīng)用程序 框架的一個內(nèi)在優(yōu)勢是對基本操作系統(tǒng)進(jìn)行了一定程度的提煉,這種提煉類似于為你提供了一種安全保證。例如, int 在 Win16 和 Win32 上分別是 2 個字節(jié)和 4 個字節(jié),無論如何,避免代碼依賴于數(shù)據(jù)類型的大小。然而,如果你想轉(zhuǎn)換代碼,要避免這種誘惑。 Microsoft Visual C++為 ANSI C 提供了一些語言細(xì)節(jié)的補(bǔ)充,例如 4 字符常數(shù)和單行的注釋。 為 Win32編寫的代碼可以在任何 Windows版本下運(yùn)行,有轉(zhuǎn)換庫時候還可以在 Macintosh下運(yùn)行。最后用一個可轉(zhuǎn)換的版本代替所有的子函數(shù)。 ? Windows 使用子窗口的概念, Macintosh 不使用子窗口。 Intel 8086 處理器 , 以及隨后衍生的 80x86 系列處理器使用 16bit 地址, 只能支持 65,536 bytes 的存儲器尋址。實(shí)踐中,因?yàn)?4byte 尋址由于太大不會一直使用, Macintosh 代碼一般分到不大于 32K 的段中存儲。在 System 7 中 , Macintosh 菜單的最右邊包含了一個 Apple 的幫助圖標(biāo),還有一個負(fù)責(zé)應(yīng)用程序之間切換的菜單。 MDI 程序的一個特點(diǎn)是子窗口最小化后,會在 MDI框架內(nèi)部產(chǎn)生一個圖