From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fee84,694e2bdb09c0ca09 X-Google-Attributes: gidfee84,public From: Niel Markwick Subject: Re: A Problem of Porting Programs from Sun Solaris 2.x to OSF1 Date: 1998/10/21 Message-ID: <362DAF40.CEA2D66C@nospam.euronet.nl>#1/1 X-Deja-AN: 403496369 Content-Transfer-Encoding: 7bit References: <362A4479.1BFE88FC@math.mun.ca> <362B3237.7E35E05@euronet.nl> To: Yingwei Peng Content-Type: text/plain; charset=us-ascii Organization: Alcatel/Bell Mime-Version: 1.0 Newsgroups: comp.unix.osf.osf1 Yingwei Peng wrote by email: > > Thank you for telling me this web site. I just read it briefly > and it seemed that I have a lot of work to do. For example, if my > understanding is correct, var2 = var1 + i is no longer valid, where > var1 and var2 are two pinters of double and i is an integer, because > of 64bit pointers in DEC!? I will check this document carefully > BTW there was no warning message when I compiled my codes. > It is not 'invalid' as such, it just may cause problems if 'i' and var2 are not defined portably (ie involving sizeof(double)) However, there are more clean and portable ways of doing this... eg if var1 is pointer to an array of double's var2 wants to be pointer to 'n'th double in the array then double *var2 = &var1[n]; will work on any platform with no problems (and is a bit more readable IMHO!) Also, remember that if var1 is a pointer returned from malloc, where the size has been non-portably defined (eg "16" instead of "4*sizeof(double)" for a 4 - double array), then there may not be enough valid memory for the required storage, so var2 will point to invalid memory. Finally, If you are going to stick with the original code, 'i' should not be an integer, but size_t (a portable scalar type used for pointer arithmetic, defined in ), and the calculation of the value of 'i' should somewhere involve 'sizeof(double)' to get the offset right! Remember, you can always exclude a bit of SOLARIS code and replace it with a DEC Unix hack with: #if (defined(__osf__) && defined(__alpha)) /* DEC Unix version of code */ #else /* other platforms */ #endif but I always feel that this is a last resort - in case someone else wants to do further porting (perhaps to a 128 bit platform!) Good luck, Niel. PS. As a humorous aside, in the past, I have been chastised for using sizeof(...) in my code - the pointy haired boss in question told me that calling sizeof so may times was a performance issue, and he wanted me to do something like: #define SIZEOF_POINTER 8 in to avoid the extra function calls! It took a LOT of persuasion to convince him that it wasn't really a function call, and the compiler simply replaced sizeof(blah) with a scalar during compilation! -- Niel Markwick (remove nospam. to reply to my email address) Consultant Software Engineer Kontich, Belgium.