Sujet : Re: Every sufficiently competent C programmer knows
De : mikko.levanto (at) *nospam* iki.fi (Mikko)
Groupes : comp.theoryDate : 13. Mar 2025, 11:25:55
Autres entêtes
Organisation : -
Message-ID : <vqubrj$36pvc$1@dont-email.me>
References : 1 2 3 4 5 6 7 8
User-Agent : Unison/2.2
On 2025-03-12 10:00:50 +0000, Richard Heathfield said:
On 12/03/2025 09:49, Mikko wrote:
On 2025-03-11 18:23:24 +0000, Richard Heathfield said:
int rhc(unsigned int i)
{
typedef int(*pf)(unsigned int);
pf arr[3] = {rha, rhb, rhc};
return arr[i % 3];
The return instruction has wrong type.
Good spot, but no, it's fine. The bug is elsewhere. That line should read:
return arr[i % 3](i);
Error corrected.
arr is of type int(*)(unsigned int)[3]
arr[i % 3] is of type int(*)(unsigned int)
arr[i % 3](i) is a function call returning int
-- Mikko