1 / 10

Драйвер

Драйвер. Реализация input_parameters. Интерфейс. input_parameters. initialization. ordering_map. Реализация initialization. some_action. finalization. namespace init{ double* df; int I,J; void input_data(); void initialization(); struct ODF; }.

Download Presentation

Драйвер

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Драйвер Реализация input_parameters Интерфейс input_parameters initialization ordering_map Реализация initialization some_action finalization namespace init{ double* df; int I,J; void input_data(); void initialization(); struct ODF; } #include “input_output.h” #include “action.h” using namespace init; namespace init{ void input_data(); void initialization(); struct ODF; } [init::input_data();]

  2. #include <iostream> #include <cmath> using namespace std; #ifdef PREC #define REAL double #else #define REAL float #endif #define df(i,j) df[j+i*J] typedef struct _odf{ REAL f; int i,j; struct odf *next; struct odf *prev; }* ODF; ODF create(REAL*); void output(ostream&,ODF); void destroy(ODF); int main(){ REAL* df; REAL T0,T1,V0,V1; REAL xb,xe,yb,ye; int I,J; char c; const REAL pi=3.14159265359;

  3. while(!cin.eof()){ cin>>c; switch(c){ case 'T': cin>>c; if(c=='0'){ cin.ignore(1024,'='); cin>>T0; } else{ cin.ignore(1024,'='); cin>>T1; } break; case 'V': cin>>c; if(c=='0'){ cin.ignore(1024,'='); cin>>V0; } else{ cin.ignore(1024,'='); cin>>V1; } break;

  4. case 'x': cin>>c; if(c=='b'){ cin.ignore(1024,'='); cin>>xb; } else{ cin.ignore(1024,'='); cin>>xe; } break; case 'y': cin>>c; if(c=='b'){ cin.ignore(1024,'='); cin>>yb; } else{ cin.ignore(1024,'='); cin>>ye; } break; case 'I': cin.ignore(1024,'='); cin>>I; break;

  5. case 'J': cin.ignore(1024,'='); cin>>J; break; default: break; } } cout<<"T0="<<T0<<"\tV0="<<V0<<"\tT1="<<T1<<"\tV1="<<V1<<endl; cout<<"xb="<<xb<<"\txe="<<xe<<"\tyb="<<yb<<"\tye="<<ye<<endl; cout<<"I="<<I<<"\tJ="<<J<<endl; df=new REAL[I*J]; int i,j; REAL x,y, hx,hy; for(i=0, hx=(xe-xb)/I, x=xb; i<I;i++, x+=hx) for(j=0, hy=(ye-yb)/J, y=yb; j<J;j++, y+=hy){ df(i,j)=exp(-( (x-V0)*(x-V0)+y*y )/2.0/T0)/pow(2.0*pi*T0,1.5)+ exp(-( (x-V1)*(x-V1)+y*y )/2.0/T1)/pow(2.0*pi*T1,1.5); } for(i=0;i<I;i++) for(j=0;j<J;j++) cout<<i<<'\t'<<j<<'\t'<<df(i,j)<<endl;

  6. ODF odf; odf=create(df); output(cout,odf); destroy(odf); delete [] df; return 0; } ODF create(REAL* df){ ODF tod=new struct _odf; tod->next=tod->prev=0; return tod; } void output(ostream& out, ODF od){ out<<"Not yet now!\n"; } void destroy(ODF od){ delete od; }

  7. Компилятор gcc, платформа LINUX Компоновка библиотеки: double a=3.1415; int sh_fun(int i){ return i*i; } //gcc -shared -fPIC 1d.c -o lib1d.so Явное связывание: #include<stdio.h> #include<stdlib.h> #include<dlfcn.h> typedefint (*fun)(int); externdouble a; int main(int argc, char* argv[]){ fun f; printf("Dynamic library test\n"); void* h=dlopen("lib1d.so",RTLD_LAZY); printf("%g\n",a); f=(fun)dlsym(h,"sh_fun"); printf("%i\n", f(5)); //int (*f)(int)=dlsym(h,"sh_fun"); //printf("%i\n", (*f)(3)); dlclose(h); return 0; } //gcc 2.c -L. -l1d -ldl -o 2 //3.1415 //25 Неявное связывание: #include<stdio.h> #include<stdlib.h> externdouble a; int sh_fun(int); int main(int argc, char* argv[]){ if(argc>1) a=atof(argv[1]); printf("%g\n",a); printf("%i\n", sh_fun(3)); return 0; } //gcc 1.c -L. -l1d -o 1 //3.1415 //9

  8. Компилятор cl (Microsoft VS) Компоновка библиотеки: #include<windows.h> extern__declspec(dllexport) int a=23; __declspec(dllexport) int f(int b){ return b*b; } __declspec(dllexport) int g(int b){ return b*b*b; } BOOL WINAPI DllMain(HANDLE hModule, DWORD dwReason, LPVOID lpReserved){ return TRUE; } //cl /c td1.c //link /DLL td1.obj

  9. Компоновка библиотеки с помощью .def-файла: #include<windows.h> int a=29; int f(int b){ return b*b*b; } int g(int b){ return b*b*b*b; } BOOL WINAPI DllMain(HANDLE hModule, DWORD dwReason, LPVOID lpReserved){ return TRUE; } //cl /c td2.c //link /DLL /DEF:td2.def td2.obj LIBRARY td2 EXPORTS a @1 f @2 g @3

  10. Явное связывание: Неявное связывание: #include<windows.h> extern__declspec(dllimport) int a; int f(int); int g(int); int main(){ printf("%i %i %i\n",a,f(3),g(3)); return 0; } //cl t1.c td1.lib #include<windows.h> typedefint (*fun)(int); int main(){ HINSTANCE hInst; fun pf,pg; int* pa; hInst=LoadLibrary("td2.dll");//("td1.dll"); pa=(int*)GetProcAddress(hInst, "a"); pf=(fun)GetProcAddress(hInst, "f"); pg=(fun)GetProcAddress(hInst, "g"); printf("%i %i %i\n",*pa,pf(3),pg(3)); FreeLibrary(hInst); return 0; } //cl t2.c kernel32.lib

More Related