C programme issue for CFD
I am writing my own CFD code using c language. I want to create a function which can deal with both single and double precision arrays such that
grad_cal1(fi1) where fi1 is an array of float grad_cal2(fi2) where fi2 is an array of double void grad_cal1(float *fi){a.h} void grad_cal2(double *fi){a.h} Inside the function, the programme is exactly the same. Is there any way to call the same function instead of two? |
Re: C programme issue for CFD
Why not simplify things by making the whole code double precision? Why do you really need to mix variable types?
|
Re: C programme issue for CFD
Hello John,
in C it is possible to compile the function with appropriate preprocessor macros, e.g. #define REAL float or #define REAL double and the corresponding definitions in the source, e.g. void grad_cal1(REAL *fi){a.h} Another (and much better) possibility would be using C++ templates. Regards, Markus |
Re: C programme issue for CFD
Markus' preprocessor approach lets you create either version independently at compile-time. To have both options simultaneously at run-time you are basically talking about object oriented programming: This is a case for C++, not C.
|
All times are GMT -4. The time now is 14:40. |