3 ms·
That seems like a very unusual way to define a function. I'd want 'ok' to be the return value, and the actual value returned to be via the pointer, since that a
by userbinator 11y ago
That seems like a very unusual way to define a function. I'd want 'ok' to be the return value, and the actual value returned to be via the pointer, since that allows for
float c;
if(get(v, &c))
...do something with c...
instead of the more verbose
bool ok;
float c;
c = get(v, &ok);
if(ok)
...do something with c...
- aciuix 11y agoI think it is a matter of being consistent. Both ways have certain syntactic dis/advantages. The first one enables you to have the function call directly in the if statement, but requires you to define a variable beforehand. The latter gives you the option to check the return value, pass a NULL, if you don't need it for example, and use the return value directly.