Vintage computing for fun and [no] profit

If it's not ZDoom, it goes here.

Re: Vintage computing for fun and [no] profit

Postby Graf Zahl » Fri Jul 02, 2021 1:19 am

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.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
 
Joined: 19 Jul 2003
Location: Germany

Re: Vintage computing for fun and [no] profit

Postby MartinHowe » Fri Jul 02, 2021 7:14 am

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 :(
User avatar
MartinHowe
In space, no-one can hear you KILL an ALIEN
 
Joined: 11 Aug 2003
Location: Waveney, United Kingdom

Re: Vintage computing for fun and [no] profit

Postby Graf Zahl » Fri Jul 02, 2021 7:17 am

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.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
 
Joined: 19 Jul 2003
Location: Germany

Re: Vintage computing for fun and [no] profit

Postby Blzut3 » Fri Jul 02, 2021 4:13 pm

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, *);
Blzut3
Pronounced: B-l-zut
 
 
 
Joined: 24 Nov 2004
Github ID: Blzut3
Operating System: Debian-like Linux (Debian, Ubuntu, Mint, etc) 64-bit
Graphics Processor: ATI/AMD with Vulkan Support

Re: Vintage computing for fun and [no] profit

Postby Graf Zahl » Fri Jul 02, 2021 4:26 pm

That code predates XCode 9 by many years. I think when I encountered the problem, XCode 8 was still a thing.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
 
Joined: 19 Jul 2003
Location: Germany

Previous

Return to Off-Topic

Who is online

Users browsing this forum: No registered users and 1 guest