On Monday, 4 July 2016 14:41:42 UTC+3, Cristiano wrote:
> Header file:
Looks like short C header (but without multiple inclusion
guards).
>
> //typedef double TIPO;
> typedef float TIPO;
>
> struct COEFF {
> TIPO *c[6];
> };
>
> struct COEFF *coe;
The keyword 'struct' is redundant in global variable 'coe'
declaration.
>
> cpp file:
>
> for(int i= 0; i < 3; i++) {
> coe[I].c[i]= new TIPO[ncoe];
> if(fread(coe[I].c[i], sizeof(TIPO), ncoe, f) != ncoe) {
> puts("ERROR"); return 3;
> }
> }
>
> const TIPO **c= (const TIPO **)coe[idx].c;
That can not compile. You can not write 'for' cycles directly
into global namespace, you have to put those inside of
functions.
> Is there any memory efficient way to rewrite the code to switch from
> float to double at runtime?
Achieve that the code compiles, then that it does what you want,
then that it does it always and accurately. Only then think how
can you achieve efficiency. It is because no one cares how fastly
and efficiently a program gives wrong answers.