* A Problem of Porting Programs from Sun Solaris 2.x to OSF1
@ 1998-10-18 4:00 Yingwei Peng
1998-10-19 4:00 ` Niel Markwick
1998-10-19 4:00 ` Finnbarr P. Murphy
0 siblings, 2 replies; 7+ messages in thread
From: Yingwei Peng @ 1998-10-18 4:00 UTC (permalink / raw)
I just wonder whether there is any body who has this experience or
not.
Recently, I tried to port my programs to OSF1 V3.2 62 alpha.
The programs run well on Sun Solaris 2.x. I can compile them on OSF1.
However, when I run them, I got "System terminating: bad address".
I traced the problem and it seemed that the problem was caused by
a function call where the function accepts an argument double **var.
I couldn't figure out what's wrong with this call or why it doesn't
on OSF1.
I heard that OSF1 is a full 64-bit system while others are not. Is
this related to my problem? I would appreciate for your advice. I am
a new user of OSF1. Thanks.
Paul.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: A Problem of Porting Programs from Sun Solaris 2.x to OSF1
1998-10-18 4:00 A Problem of Porting Programs from Sun Solaris 2.x to OSF1 Yingwei Peng
@ 1998-10-19 4:00 ` Niel Markwick
1998-10-21 4:00 ` Niel Markwick
1998-10-19 4:00 ` Finnbarr P. Murphy
1 sibling, 1 reply; 7+ messages in thread
From: Niel Markwick @ 1998-10-19 4:00 UTC (permalink / raw)
To: Yingwei Peng
Yingwei Peng wrote:
> Recently, I tried to port my programs to OSF1 V3.2 62 alpha.
> The programs run well on Sun Solaris 2.x. I can compile them on OSF1.
> However, when I run them, I got "System terminating: bad address".
There is a very useful 'Sun Solaris to DIGITAL UNIX Porting Guide'
document which can be downloaded from:
http://www.digital.com/hpc/ref/refdoc.html#porting
Your problem will probably be related to sizes of the various types:
check for hardcoded sizes in malloc's instead of n*sizeof(type), and for
passing an int*/float* to a function expecting long*/double*. Take note
of compiler warnings also!
Good luck,
Niel.
--
Niel Markwick
Consultant Software Engineer
Kontich, Belgium.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: A Problem of Porting Programs from Sun Solaris 2.x to OSF1
1998-10-18 4:00 A Problem of Porting Programs from Sun Solaris 2.x to OSF1 Yingwei Peng
1998-10-19 4:00 ` Niel Markwick
@ 1998-10-19 4:00 ` Finnbarr P. Murphy
1 sibling, 0 replies; 7+ messages in thread
From: Finnbarr P. Murphy @ 1998-10-19 4:00 UTC (permalink / raw)
A Solaris to Digital UNIX porting guide can be found at
http://www.unix.digital.com/faqs/publications/porting/HTML/solaris.html
Finnbarr
>Recently, I tried to port my programs to OSF1 V3.2 62 alpha.
>The programs run well on Sun Solaris 2.x. I can compile them on OSF1.
>However, when I run them, I got "System terminating: bad address".
>I traced the problem and it seemed that the problem was caused by
>a function call where the function accepts an argument double **var.
>I couldn't figure out what's wrong with this call or why it doesn't
>on OSF1.
>
>I heard that OSF1 is a full 64-bit system while others are not. Is
>this related to my problem? I would appreciate for your advice. I am
>a new user of OSF1. Thanks.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: A Problem of Porting Programs from Sun Solaris 2.x to OSF1
1998-10-19 4:00 ` Niel Markwick
@ 1998-10-21 4:00 ` Niel Markwick
1998-10-21 4:00 ` Timo Felbinger
0 siblings, 1 reply; 7+ messages in thread
From: Niel Markwick @ 1998-10-21 4:00 UTC (permalink / raw)
To: Yingwei Peng
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 <stddef.h>), 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.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: A Problem of Porting Programs from Sun Solaris 2.x to OSF1
1998-10-21 4:00 ` Niel Markwick
@ 1998-10-21 4:00 ` Timo Felbinger
1998-10-21 4:00 ` Niel Markwick
0 siblings, 1 reply; 7+ messages in thread
From: Timo Felbinger @ 1998-10-21 4:00 UTC (permalink / raw)
On Wed, 21 Oct 1998, Niel Markwick wrote:
> 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!)
In C, both
var1[n]
and
*(var1+n)
have the same effect; when adding an integer to a pointer, the size of what
this pointer points to will be taken into account automatically. What's more,
you can even write
n[var1]
this, too, is equivalent to *(var1+n).
In other words, if both var1 and var2 are arrays of double, you may write
7[var2] = 4[var1]
to copy the value of the 4th element of var1 into the 7th element of var2.
Yes, I know this is ugly and I didn't believe it when I saw it the first
time, but nothing in the language standard forbids it, and at least some
compilers will actually accept this (I tested this with gcc 2.8.1).
Of course, &var1[n] may well be the most readable way to code.
> 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.
True.
> 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 <stddef.h>), and the calculation of the value of
> 'i' should somewhere involve 'sizeof(double)' to get the offset right!
Using size_t instead of int is a good idea, but you will certainly not
have to involve sizeof(double) to get the correct offset for a pointer
into an array of double!
> 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!
Could have been worse. A really pointy haired boss would have asked you
to do it in a more portable way (avoiding the hard-coded constant 8):
int sizeof_pointer;
main() {
sizeof_pointer = sizeof(int *);
.
.
.
}
and use the global variable whenever you need the size of a pointer ;-)
Timo Felbinger (Timo.Felbinger@quantum.physik.uni-potsdam.de)
Quantum Physics Group
Institute of Physics
University of Potsdam, Germany
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: A Problem of Porting Programs from Sun Solaris 2.x to OSF1
1998-10-21 4:00 ` Timo Felbinger
@ 1998-10-21 4:00 ` Niel Markwick
0 siblings, 0 replies; 7+ messages in thread
From: Niel Markwick @ 1998-10-21 4:00 UTC (permalink / raw)
Timo Felbinger wrote:
>
> In C, both
> var1[n]
> and
> *(var1+n)
> have the same effect; when adding an integer to a pointer, the size of what
> this pointer points to will be taken into account automatically.
Whoops!
Thanks Timo - I had forgotten about that...
Probably because all the pointers in the code I was porting were void*'s
and char*'s and were only cast to the proper type after all the
arithmetic had been done to get them to point to something reasonable...
Niel
--
Niel Markwick (remove nospam. to reply to my email address)
Consultant Software Engineer
Kontich, Belgium.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: A Problem of Porting Programs from Sun Solaris 2.x to OSF1
@ 1998-10-24 4:00 Yingwei Peng
0 siblings, 0 replies; 7+ messages in thread
From: Yingwei Peng @ 1998-10-24 4:00 UTC (permalink / raw)
A few days ago I posted a question with regard to port programs
from Solaris to OSF1. I have got two replies and both directed me
to a document "Sun Solaris to DIGITAL UNIX Porting Guide".
I have checked my programs following the guidelines in the
document. However my problem is still there.
I found that the problem relates to the following function.
int cholesky(double **matrix, int n)
{
... ...
}
Whenever this function is called, my program stops and prints
a message "System terminating: bad address". I can print values
stored in "matrix" and "n" variables before the function call.
So I couldn't see why the program stops. Is there any body who
has experience with this type of problem? Please give me a clue
to help me out. Thanks a lot.
Paul.
Note: the program runs well on Solaris and Intel-based PCs.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~1998-10-24 4:00 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1998-10-18 4:00 A Problem of Porting Programs from Sun Solaris 2.x to OSF1 Yingwei Peng
1998-10-19 4:00 ` Niel Markwick
1998-10-21 4:00 ` Niel Markwick
1998-10-21 4:00 ` Timo Felbinger
1998-10-21 4:00 ` Niel Markwick
1998-10-19 4:00 ` Finnbarr P. Murphy
-- strict thread matches above, loose matches on Subject: below --
1998-10-24 4:00 Yingwei Peng
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox