Page 6 of 6

Re: Vintage computing for fun and [no] profit

PostPosted: Fri Jul 02, 2021 1:19 am
by Graf Zahl
The -O3 myth comes from a certain breed of programmers who do not consider code proper unless they have added some weird hacks exploiting compiler quirks and other undefined behavior.
Sadly these people still exist - and the software they write is full of problems.

Here's a great example I found in some utility code my work project used to detemine iOS's version number:

Code: Select allExpand view
#if 0
   // Let this be a monument for the worst method ever devised to check the OS's version number.
   NSString *systemVersion = [[UIDevice currentDevice] systemVersion];
   NSArray *splitArray = [systemVersion componentsSeparatedByString:@"."];
   
   
   BOOL isiOS10OrHigher = NO;
   if (splitArray && [splitArray count] > 0) {
      if ([splitArray[0] intValue] >= 10) {
         isiOS10OrHigher = YES;
      }
   }
   
   if (!isiOS10OrHigher)
   {
      isiOS10OrHigher =  [[[UIDevice currentDevice] systemVersion] rangeOfString:@"10."].location != NSNotFound;
   }
#else
   BOOL isiOS10OrHigher =  [[[UIDevice currentDevice] systemVersion] floatValue] >= 10;
#endif


First block: what was found, and what broke when iOS upgraded to 11.
Second block: the correct check.

Re: Vintage computing for fun and [no] profit

PostPosted: Fri Jul 02, 2021 7:14 am
by MartinHowe
Should I :lol:, :shock:, or :roll: ? Seriously, that's crazy. Sadly, MANY configure scripts out there in Linux land do much the same kind of thing; for example, failing to detect modern compilers such as GCC 10 because the script is checking a 'version string' for [1-9].*, that sort of thing. Seen a lot of this when compiling older (and not so older) software on the AlphaServer; it's like the Y2K all over again :(

Re: Vintage computing for fun and [no] profit

PostPosted: Fri Jul 02, 2021 7:17 am
by Graf Zahl
My reaction was more like :bang: - that thing cost me half a day of work to track down and fix when it started to cause problems.

Re: Vintage computing for fun and [no] profit

PostPosted: Fri Jul 02, 2021 4:13 pm
by Blzut3
Assuming you're building with Xcode 9 or newer even that is overly complicated, these days I believe that can be written as just:
Code: Select allExpand view
BOOL isiOS10OrHigher = @available(iOS 10, *);

Re: Vintage computing for fun and [no] profit

PostPosted: Fri Jul 02, 2021 4:26 pm
by Graf Zahl
That code predates XCode 9 by many years. I think when I encountered the problem, XCode 8 was still a thing.