View Single Post
Old Nov 12th, 2007, 6:28 AM   #10
Gabriel Margarido
Newbie
 
Join Date: Nov 2007
Posts: 9
Rep Power: 0 Gabriel Margarido is on a distinguished road
Re: Incompatible pointer type (double pointer in a function)

I'll try to answer both posts at once.

Yes, DaWei, I understand the issues of this problem. I had the program working, but using mostly dynamic allocation. Thus, If I allocated a matrix with double **H in the main part of the program and then passed it to function H2, I think (as you said) the compiler assumed I knew what I was doing. When I changed the allocation to double H[4][4], I thought the compiler would still understand that. With other languages, that's what would happen.
I wanted, if possible, to change my functions as little as possible, but I understand I'll have to do some pointer arithmetic. No problem with that .

Harakim, thank you for your ideas. The first two work in this case, but are not general enough for the rest of the code. Yes, the third works in gcc... I was just trying to avoid it (for portability purposes).
I know the code can (must) be changed. I won't, for example, calculate r*(1-r) so many times (several elements of the matrix are exactly the same). I'll also use logarithms to work with sums rather than multiplications (r can be really small).

Overall, now I understand the path to follow. All your ideas were most valuable! As a plant breeder, I have some trouble with programming in C... But my code is for an iterative process that can run for quite some time, so I need it to be fast.

Regards,
Gabriel.
Gabriel Margarido is offline   Reply With Quote