Create an account


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

#1
So writing some code i have been reading up on how to not make it perform badly by default and came across this site http://ouns.nexuizninjaz.com/dev_quakec.html#if-chains 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.
Reply

#2
Your reference is not up to date, here's the relevant page in the Xonotic wiki: http://dev.xonotic.org/projects/xonotic/..._to_QuakeC

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.
Reply

#3
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.
Reply



Possibly Related Threads…
Thread Author Replies Views Last Post
  What was easy for you in development? (Darkplaces and QuakeC programming) LegendGuard 2 3,059 08-08-2020, 05:25 PM
Last Post: LegendGuard
  [TUTORIAL] How to create a command - Xonotic QuakeC programming LegendGuard 3 3,703 07-25-2020, 06:24 PM
Last Post: LegendGuard
  Moving away from QuakeC Lyberta 11 10,844 07-17-2020, 07:36 AM
Last Post: LegendGuard
  [NEED HELP] [Commission] To update Jeff's Modpack - QuakeC programmer wanted breakfast 4 5,345 07-08-2020, 12:45 PM
Last Post: breakfast
  New QuakeC virtual machine Lyberta 5 7,645 07-14-2017, 04:01 PM
Last Post: poVoq
Brick A script engine written in QuakeC Melanosuchus 9 13,528 10-14-2014, 02:01 AM
Last Post: Melanosuchus
  QuakeC: Variadic macros? WannabeUser 2 3,930 03-10-2014, 05:16 PM
Last Post: WannabeUser
  Learning QuakeC? phim 13 20,493 12-24-2013, 03:07 AM
Last Post: aa
  A question of getting started with Quakec timetopat 5 8,002 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-