Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!mips!pacbell.com!lll-winken!jac@moonshine.llnl.gov From: jac@gandalf.llnl.gov (James A. Crotinger) Newsgroups: comp.lang.c++ Subject: Re: 64 bit architectures and C/C++ Message-ID: Date: 2 May 91 19:49:06 GMT References: <13261@goofy.Apple.COM> <1991May1.163446.20707@ccad.uiowa.edu> Sender: usenet@lll-winken.LLNL.GOV Lines: 44 Nntp-Posting-Host: sundance.llnl.gov cadsi@ccad.uiowa.edu (CADSI) writes: > to further these comments note that on a CRAY, a (char *) is a bit-packed > structure itself. In particular, the lower 48 bits are a pointer to > the word in memory where the character exists. The top 3 bits of the > 64-bit pointer are an index to the byte of the word of the actual > character. Thus, an (int *) cannot be conveniently cast to a (char *). > I hate it when that happens. And in Fortran, they also pack the string length into the word (only 32 bits are used for the word address). And the really awful thing is that this packing scheme is different on the X/Y-MP class machines than on the CRAY-2 machines. (I think the format for char *'s is different as well). Ack! As an aside, I wrote a nifty C++ class called FCD (Fortran character descriptor) which makes calling Fortran routines from C++ much cleaner. You prototype the fortran functions as taking FCD's rather than char *'s: void FORTRANFUNCTION( int &num, FCD string ); Then you just call it with your char *: main() { char * foo = "Hello"; FORTRANFUNCTION( 3, foo + 1 ); // Would break if this had been prototyped // to take a char *. } The FCD class has an inline constructor which converts the char * to an FCD. Much nicer than the hoops you have to jump through when using C. Unfortunately, the mechanism used by Sun (and other UNIXes?) for passing string lengths in Fortran is completely different. Rather than passing a structure containing the pointer and the length, they push the lengths onto the stack after pushing all the other args. This makes writing portable C++ code which interacts with Fortran libraries a pain. Jim -- ----------------------------------------------------------------------------- James A. Crotinger Lawrence Livermore Natl Lab // The above views jac@moonshine.llnl.gov P.O. Box 808; L-630 \\ // are mine and are not (415) 422-0259 Livermore CA 94550 \\/ necessarily those of LLNL