How does compilers optimizes theese 4 types of function definitions. Is there any optimization done in sense of argument passing?
int check_collision(const SDL_Rect const *A,const SDL_Rect const *B) { ... }
int check_collision(SDL_Rect const *A,SDL_Rect const *B) { ... }
int check_collision(const SDL_Rect *A, SDL_Rect const *B) { ... }
int check_collision(SDL_Rect *A, SDL_Rect *B) { ... }
And if it matters, what do you think would be the preferable way of passing read only arguments to a function in cases where these argument might inefficent to copy when calling the funcion?
Use
constin any of these cases to indicate the purpose of your usage more clearly and writing more readable code, modern day compilers are efficient and smart enough to apply required optimization’s whether you pass the function argument asconstor not.In short, use
constin this case for readability & preventing usage errors, & not for compiler optimization,Compiler is smart enough to take care of that.