Difference between revisions of "Portability issues"

From RogueBasin
Jump to navigation Jump to search
m (→‎Memory: IRIX is all-capped. The issue of writing to NULL is only of interest to certain languages that even allow it.)
m (Remove duplicate title text.)
 
(16 intermediate revisions by 10 users not shown)
Line 1: Line 1:
Portability Issues
The purpose of this article is to collect portability issues often encountered by roguelike programmers as well as possible solutions for these problems.
The purpose of this article is to collect portability issues often encountered by roguelike programmers as well as possible solutions for these problems.


== Memory ==
== Memory ==


* Some [[Operating Systems]], such as IRIX, allow the programs to read from a [[NULL address]], while others will [[segfault]] instantly.  Trying to write to a [[NULL address]] will hopefully always cause a [[segfault]].  (Except on many embedded systems.  The Gameboy Advance, for example, will not [[segfault]] on a [[NULL address]] write.)
* Some [[Operating systems]], such as IRIX, allow the programs to read from a [[NULL address]], while others will [[segfault]] instantly.  Trying to write to a [[NULL address]] will hopefully always cause a [[segfault]].  (Except on many embedded systems.  The Gameboy Advance, for example, will not [[segfault]] on a [[NULL address]] write.)


== Display ==
== Display ==
Line 11: Line 9:
* Only the characters of the basic (7bit) ASCII character set are reasonably portable. Using characters from extended character sets (like the solid blocks from the IBM DOS character set) or characters which aren't classified as printable by the ASCII standard (like the smileys from IBM DOS) will probably cause problems.
* Only the characters of the basic (7bit) ASCII character set are reasonably portable. Using characters from extended character sets (like the solid blocks from the IBM DOS character set) or characters which aren't classified as printable by the ASCII standard (like the smileys from IBM DOS) will probably cause problems.
** Extensions to ASCII are not portable.  Unicode is portable, though, plus it includes all the old IBM DOS characters, though not necessarily at the same code points.
** Extensions to ASCII are not portable.  Unicode is portable, though, plus it includes all the old IBM DOS characters, though not necessarily at the same code points.
* [[Output libraries]] discusses the options you have.


== Filesystem ==
== Filesystem ==


* Some [[Operating Systems]] (such as any that derive from or pattern [[UNIX]] or follow [[POSIX]] standards) are case-sensitive as far as filenames are concerned.  Others (like [[DOS]] or [[Windows]]) are case-insensitive.  Still others (like HFS+, in common use on [[OS X]]) preserve case but are insensitive to it. One shouldn't rely on any one case behavior to achieve maximum portability.
* Some [[Operating systems]] (such as any that derive from or pattern [[UNIX]] or follow [[POSIX]] standards) are case-sensitive as far as filenames are concerned.  Others (like [[DOS]] or [[Windows]]) are case-insensitive.  Still others (like HFS , in common use on [[Mac OS X | OS X]]) preserve case but are insensitive to it. One shouldn't rely on any one case behavior to achieve maximum portability.
* There are [[Operating Systems]] that forbid use of certain characters within file names, most often path separators (e.g., colons in Classic MacOS). Other characters may require "escaping" in filename references.
* There are [[Operating systems]] that forbid use of certain characters within file names, most often path separators (e.g., colons in Classic [[Mac OS]]). Other characters may require "escaping" in filename references.
* [[Operating Systems]] may also restrict filename length or the total length of an absolute filepath.
* [[Operating systems]] may also restrict filename length or the total length of an absolute filepath.
* [[DOS]] and [[Windows]] differ in their [[path separator]] — a ''backslash'' ('\') — from the [[POSIX]] separator, the ''slash'' ('/').
* [[DOS]] and [[Windows]] use backslash as their path separator while [[UNIX]] uses slash. Most Windows APIs will understand the forward slash as a path separator, however.
* Note that most modern operating systems allow files with spaces in them.  This means if you pass arguments to another program you should be able to protect those arguments if they may contain spaces.  Ie, if a user names themselves "Foo Bar", your save file may be "Foo Bar.sav".  On Windows, it is quite likely that your path will have a space in it, as several system-standard directories utilize this feature (e.g., "Program Files").
[[Category:Articles]]
 
== Input ==
 
* Use of the Escape key should be avoided, because escape is a [[special character]] for many of the terminals that roguelikes are traditionally played on.  These terminals sometimes must hold up an escape key to see if it should be processed or passed on, and that causes annoying delays in a user interface that uses Escape.
 
* Which characters are used to indicate the end of a line in text files is [[OS-specific]]. One has to be careful when [[parsing text files]].
 
* Remember that there are more than one keyboard layout in the world.  A lot of international keyboards have different mappings than the US version that most people take for granted.  Shift-., for example, is ; on a Finnish keyboard and > on a US keyboard. ''See a survey on [[PreferredKeyControls]]''


== Mac OS X ==
== Sockets / Networking ==


* The current version of the standard [[OS X]] terminal (Terminal.app) only supports 8 colors. Early versions of the bundled [[OS X]] [[curses library]] did not support color at all.
If you use socket-related system calls directly, you will need to change your code a bit for different platforms:


== DOS ==
* [[Windows]] uses different header files under C/[[Cpp]]. The following will work under mingw32.
    #ifdef WIN32
        #include <winsock2.h>
        typedef int socklen_t;
    #else
        #include <sys/socket.h>
        #include <netinet/in.h>
        #include <arpa/inet.h>
        #include <netdb.h>
    #endif
* You will need to call the following before any standard socket code:
    WSADATA wsaData;
    WSAStartup(MAKEWORD(2,2), &wsaData);
* And the following on exit:
    WSACleanup();
* And as a handy hint, sleep:
    #include <windows.h>
    #define sleep(n) Sleep(1000 * n)


* Filenames are limited to 8 characters + a 3 characters extension. Additionally filenames must not contain whitespace or [[DOS special characters]].
However, it is often a good idea to use a higher-level interface, such as SDL_net, instead. These are easier to work with and more portable.
* Memory in the [[processor's real mode]] is tight and inconveniently segmented.  Later models had a variety of schemes available for accessing [[expanded memory]] or [[extended memory]], but being maximally portable to this platform means using less than 640KB of RAM.

Latest revision as of 02:31, 19 May 2017

The purpose of this article is to collect portability issues often encountered by roguelike programmers as well as possible solutions for these problems.

Memory

Display

  • Only the characters of the basic (7bit) ASCII character set are reasonably portable. Using characters from extended character sets (like the solid blocks from the IBM DOS character set) or characters which aren't classified as printable by the ASCII standard (like the smileys from IBM DOS) will probably cause problems.
    • Extensions to ASCII are not portable. Unicode is portable, though, plus it includes all the old IBM DOS characters, though not necessarily at the same code points.
  • Output libraries discusses the options you have.

Filesystem

  • Some Operating systems (such as any that derive from or pattern UNIX or follow POSIX standards) are case-sensitive as far as filenames are concerned. Others (like DOS or Windows) are case-insensitive. Still others (like HFS , in common use on OS X) preserve case but are insensitive to it. One shouldn't rely on any one case behavior to achieve maximum portability.
  • There are Operating systems that forbid use of certain characters within file names, most often path separators (e.g., colons in Classic Mac OS). Other characters may require "escaping" in filename references.
  • Operating systems may also restrict filename length or the total length of an absolute filepath.
  • DOS and Windows use backslash as their path separator while UNIX uses slash. Most Windows APIs will understand the forward slash as a path separator, however.

Sockets / Networking

If you use socket-related system calls directly, you will need to change your code a bit for different platforms:

  • Windows uses different header files under C/Cpp. The following will work under mingw32.
   #ifdef WIN32
       #include <winsock2.h>
       typedef int socklen_t;
   #else
       #include <sys/socket.h>
       #include <netinet/in.h>
       #include <arpa/inet.h>
       #include <netdb.h>
   #endif
  • You will need to call the following before any standard socket code:
   WSADATA wsaData;
   WSAStartup(MAKEWORD(2,2), &wsaData);
  • And the following on exit:
   WSACleanup();
  • And as a handy hint, sleep:
   #include <windows.h>
   #define sleep(n) Sleep(1000 * n)

However, it is often a good idea to use a higher-level interface, such as SDL_net, instead. These are easier to work with and more portable.