yes you are completely right, in case that the difference goes in direction to MAXINT/2 this will NOT work any more... .
But my hook counter difference for sure is well below 10000, so far far away from MAXINT/2, then this works nicely... .
Thank you for your solution, you are right, your solution is somehow better as it will work also for differences above MAXINT/2 ... just generally in our software I typically in such case would also include an assert (at least in debug compile) which would alarm me if the resulting difference even is above MAXINT/4... in such case better already the "red alarm lights" should start to blink :).
For 64 bit values you fortunately really will NOT have this problem any more, at least if you think of time scale in milliseconds, which was the typical challenge in 32bit world for this problem... but in 32bit software this really is always an issue as soon as date/calender functions come up... . (if you do motor control applications with encoders, this also can quite easily happen if for fine-tune control algorithms you have the ambition to use int values with sub-micrometer encoder resolution...).