Penguin
Diff: CPortabilityNotes
EditPageHistoryDiffInfoLikePages

Differences between current version and predecessor to the previous major change of CPortabilityNotes.

Other diffs: Previous Revision, Previous Author, or view the Annotated Edit History

Newer page: version 7 Last edited on Friday, July 7, 2006 9:44:45 am by AristotlePagaltzis
Older page: version 6 Last edited on Saturday, March 26, 2005 7:24:44 pm by JohnMcPherson Revert
@@ -1,35 +1 @@
-This page describes some programming hints that might help you to write more portable [C ] code .  
-  
-  
-!!!File Handling  
-  
-!File locking  
-  
-[BSD]-style unixes uses flock(2), which uses "advisory" locks. Ie, a process with sufficient read or write permission can ignore the lock and read/write a file. [SysV]-style unixes use either advisory locks or "mandatory" locks (if enabled in the filesystem), and access them by the fcntl(2) command and a <tt>struct flock</tt> object.  
-  
-A more portable way (POSIX 1003.1-2001) is to use the lockf(3) function from unistd.h, which will do the correct type of locking for the unix it is compiled on. (In Linux/GNU libc, this function is a wrapper around fcntl(2)).  
-  
-!!!printf types  
-!64bitisms and fixed sized types  
-If you have a fixed sized type (eg, uint64_t) and you want to use printf to display it, you need to know the real type of the integer. eg:  
-<verbatim>  
- uint64_t x;  
- printf("%llu",x);  
-</verbatim>  
-This however will fail on 64bit machines as uint64_t is "long" not "long long".  
-  
-POSIX defines some macros to use in this case, normally found in inttypes.h. Eg, for an unsigned 64 bit value, use the macro PRIu64. This will  
-be substituted for whatever is appropriate on your host - either lu or llu, depending on if you are on a 32bit or 64bit host.eg:  
-<verbatim>  
- uint64_t x;  
- printf("%"PRIu64,x);  
-</verbatim>  
-  
-----  
-Other pages:  
-  
-* HP has a set of C portability notes [online|http://docs.hp.com/en/5074/portability.html], although it targets HP-UX.  
-* Intel has a similar set of notes [online|http://www.intel.com/cd/ids/developer/asmo-na/eng/technologies/64bit/200519.htm?page=1] (for porting to [ia64] and [amd64])  
-  
-----  
-Part of CategoryProgramming  
+Describe [CPortabilityNotes ] here