随笔-57  评论-12  文章-0  trackbacks-0
1. Difference among Different Platforms

1) Different compilers ( pls read the makefiles of hspice)

2) Create a lib

Normally:
$(AR) $(TARGET_LIB) %.o

Exception: (while create C++ lib)

SunOS :
$(CXX) -xar -o $(TARGET_LIB) %.o
SGI:
$(CXX) -ar -o $(TARGET_LIB) %.o

Explanation :

SunOS :
-xar Creates archive libraries.

When building a C++ archive that uses templates,
it is necessary in most cases to include in the
archive those template functions that are instan-
tiated in the template repository. Using this
option automatically adds those templates to the
archive as needed.

Examples:

The following command archives the template func-
tions contained in the repository and the object
files.

example% CC -xar -o libmain.a a.o b.o c.o

Warnings:

Do not add .o files from the template repository
on the command line.

Do not use the ar command directly for building
archives. Use CC -xar to ensure that template
instantiations are automatically included in the
archive.

SGI:
-ar may be the same.

3) C++

1) Include head files
HP-UX & SGI :
#include <iostream.h>
#include <fstream.h>
#include <iomanip.h>
Others :
#include <iostream>
#include <fstream>
#include <iomanip>

2) using namespace std;
HP-UX does not support namespace.

3) On ALPHA & IBM, the fstream class has no the following constructor:

fstream(int fd);

2. Mixed Language Program

1) Function Name Modification among C, FORTRAN and C++

Focus on file src_metaq/ftnc.h:

Linux,PC,HP,IBM :
#define FTNC(f) f

SUN,SGI :
#ifdef __STDC__ /* Ansi C */
#define FTNC(f) f##_
#else
#define FTNC(f) f_
#endif

ALPHA :
#define FTNC(f) f##_

#define FCALL(f) FTNC(f)

2) extern "C"
In C++ program,use this to compile C++ function or others to C format.
Thus,C can call C++ function,and C++ can call C function.

Examples:

extern "C" void foo1(void);
extern "C" int FTNC(foo2)(void);

extern "C"
{
void foo1(void);
int FTNC(foo2)(void);
...
}

extern "C"
{
#include "foo1.h"
#include "foo2.h"
...
}

3) FORTRAN call C, C++ (UNIX)

C: void FTNC(foo)(int *,double*);
F: external foo
call foo(...)

C++: extern "C" void FTNC(foo)(int*,double*);
F: external foo
call foo(...)

4) C,C++ call FORTRAN (UNIX)

F: subroutine foo(...)

C: void FTNC(foo)(...)
FTNC(foo)(...);

C++:extern "C" FTNC(foo)(...)
FTNC(foo)(...);

3.PC Porting

1) FORTRAN call C, C++
Focus on src_header/refs.dek ( Only used on PC )

Should include header file refs.dek in fortran files.

C: void FTNC(foo1)(int *arg1,double *arg2,char *arg3);
int FTNC(foo2)(int *arg1,double *arg2,char *arg3);

In refs.dek:

INTERFACE TO SUBROUTINE foo1
+ [C,ALIAS:'_foo1'] (arg1,arg2,arg3)
INTEGER*4 arg1 [REFERENCE]
DOUBLE PRECISION arg2 [REFERENCE]
CHARACTER*8 arg3 [REFERENCE]
END

INTERFACE TO INTEGER*4 FUNCTION foo2
+ [C,ALIAS:'_foo2'] (arg1,arg2,arg3)
INTEGER*4 arg1 [REFERENCE]
DOUBLE PRECISION arg2 [REFERENCE]
CHARACTER*8 arg3 [REFERENCE]
END

F: external foo1
external foo2
integer foo2

call foo1(...)
ret=foo2(...)

2) C, C++ call FORTRAN
Focus on src_header/fortran2c.h

F: subroutine foo(a,b)
integer*4 a
double precision b

i) C: #define foo FTNC(FOO)
extern foo(); (default cdecl)
foo(...);

ii)C: #define foo FTNC(FOO)
extern __stdcall void foo(int *a,double *b)

foo(...);

3) C, C++ call FORTRAN (Special Case)
F: subroutine foo(a,b)
integer*4 a
character b

C: extern __stdcall void foo(int *a,char *b,char *b1)

Explanation:
Fortran : _foo@nn (nn -- length of stack)
C : : -foo@mm (mm -- length of stack)
mm should equal nn.
But in Fortran: charactor --> 8 bytes
in C, C++: char * --> 4 bytes

So,double char * to supply 8 bytes

posted on 2006-04-13 17:49 Martin 阅读(403) 评论(0)  编辑 收藏 引用 所属分类: Project Management
只有注册用户登录后才能发表评论。