c164-1bj@cordelia.berkeley.edu (Jonathan Dubman) (10/30/87)
OK, let's get this straight once and for all: 1. What is the difference between a C pointer and a BPTR? 2. What is the difference between a sensible C string and a BSTR? 3. Are there any other differences I have to worry about when playing with AmigaDOS function calls? *&Jonathan Dubman Got an extension on the semantic analyzer!
dillon@CORY.BERKELEY.EDU (Matt Dillon) (10/31/87)
> 1. What is the difference between a C pointer and a BPTR? A BPTR is a C pointer shifted right by two (divided by 4). This is why many structure's must be 'longword aligned'... so DOS can have BPTR's to them. (Aztec C): #define BTOC(ptr) ((void *)((long)(ptr)<<2)) #define CTOB(ptr) ((void *)((long)(ptr)>>2)) > 2. What is the difference between a sensible C string and a BSTR? A C string ends with a \0. A BSTR does not end with anything... the first character (unsigned) of a BSTR is the length of the string. For example, "ABC" would be: 03 41 42 43 (hex) Usually you have a BPTR to a BSTR, which means that the first character (the length) must be longword aligned. > 3. Are there any other differences I have to worry about when > playing with AmigaDOS function calls? returned structures such as file handles, locks, and seglists, are BPTR's. After converting a SegList BPTR to a C pointer, remember that the first longword is a linked list 'next' pointer... so actual code starts at offset 4 from the C pointer (offset 1 from the BPTR).... You need to know this when you use CreatProc(). codestart = (long)BTOC(Seglist)+4 OR codestart = BTOC((long)Seglist+1) (same difference) -Matt