The meaning of "const" prefix in a function header
#1

So as I understood, the "const" prefix declares a variable as a constant which means that it can't be modified. I've noticed it is used in many functions such as GetPlayerName or GetWeaponName and that's what confuses me. I know that arrays are always passed to functions as references so the "const" is used as a guard against unintentional modifications. But why do these functions have it then?

GetWeaponName(weaponid, const weapon[], len)
GetPlayerName(playerid, const name[], len)

To use those functions, you first create an array, then you pass that array to it and it modifies it. How can it modify it if it's prefixed with "const"? When I tried to make my own function that should work like this, there was an error when I tried to use "format" on that const array: error 035: argument type mismatch (argument 1). So it really couldn't be modified until I removed "const" prefix from the header. Why do those functions mentioned above work normally with it then?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)