Create an account

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
QuakeC: if chains?

So writing some code i have been reading up on how to not make it perform badly by default and came across this site that says:

Quote:With default compile options (i.e. if the option -flo is not passed to the compiler), boolean expressions are evaluated fully.

They also mention fteqcc so i am wondering if this is something i have to worry about using gmqcc beyond that expressions that can have sideeffects (containing functions or assignments) will have them regardless of order (which i guess cant be changed as some code might rely on the sideeffects). Where i am getting is: Can i write something like if( somevar && someother && yetanother ) assuming the compiler will chose the best possible bytecode (say no possible sideeffects -> if chain - assuming that actually is the most efficient bytecode) or will it be auto performance loss for not writing if( somevar ) if( someother ) if( yetanother ) because the compiler is not clever enough or for some weird technical reason cant optimize it? The gmqcc "documentation" sadly wasnt exactly helpful so i thought it might not hurt to ask.

Somewhat related: Is there a reason to avoid switch? I have seen looooong if-else-if constructs. Is this just a preference of the authors or maybe some historical thing or is there more to it? Switch being closely related to if kinda got me curious.

Also somewhat related: Is this something i should worry about at all? I guess instantly doubting the compilers abilities to optimize stuff is kind of a bad c habit.

Your reference is not up to date, here's the relevant page in the Xonotic wiki:

It's still based on FTEQCC though. Someone should fix that.

Anyway, gmqcc's manpage (or at least a months-old version of it) mentions
Quote: -fshort-logic
Perform early out in logical AND and OR expressions. The final result will be either a 0 or a 1, see the next flag for more possibilities.
which is what you mean.

Looking at the source code, it seems that SHORT_LOGIC is enabled for -std=gmqcc, which Xonotic uses. Looks like the docs aren't up to date on this.
[Image:]640K ought to be enough for anybody.
     ― Linux Torvalds

Ouch, how could i miss that? You are right, its just above -fperl-logic which ironically i read at least 3 times thinking "no this really isnt what i am looking for". I guess i owe the gmqcc documentation an apology now. Thanks a lot for clarifying. This would have cost me time on pretty much every single if statement trying to decide if i am going to build this ugly if-if-if construct just to be sure or if i will take the risk of doing it the normal way.

Possibly Related Threads...
Thread Author Replies Views Last Post
  [NEED HELP] [Commission] To update Jeff's Modpack - QuakeC programmer wanted breakfast 5 1,204 07-08-2020, 12:45 PM
Last Post: breakfast
  Moving away from QuakeC Lyberta 14 3,297 06-22-2020, 06:50 AM
Last Post: poVoq
  [TUTORIAL] How to create a command - Xonotic QuakeC programming LegendGuard 1 421 05-27-2020, 03:55 AM
Last Post: BuddyFriendGuy
  New QuakeC virtual machine Lyberta 8 3,433 07-14-2017, 04:01 PM
Last Post: poVoq
Brick A script engine written in QuakeC Melanosuchus 9 7,768 10-14-2014, 02:01 AM
Last Post: Melanosuchus
  QuakeC: Variadic macros? WannabeUser 2 2,228 03-10-2014, 05:16 PM
Last Post: WannabeUser
  Learning QuakeC? phim 13 13,438 12-24-2013, 03:07 AM
Last Post: aa
  A question of getting started with Quakec timetopat 5 5,469 07-02-2012, 07:55 AM
Last Post: timetopat

Forum Jump:

Users browsing this thread:
1 Guest(s)

Forum software by © MyBB original theme © iAndrew 2016, remixed by -z-