Reputation: 425
I'm developing a piece of code which makes scientific calculation, and as a result I use extensive use of double
variables. These variables travel from function to function, but most of them are never modified and hence defined as const
in function signatures.
I have used double*
in function signatures, but then I started to wonder that whether it's better to use double
instead because:
double*
and double
are same size, 8 bytes in C++.double*
, I need another fetch operation in the function.When using the variables in const
fashion, are there any valid reasons to use double*
instead of double
?
Upvotes: 1
Views: 11426
Reputation: 425
Here's the crust of the matter:
const
, if you need to change the variable later, it's extra refactorization work, nevertheless const correctness is important.Upvotes: 1