.qc (dot qc) - the group for quake c coders of all denominations. If you make quake one mods and write code in quake c, join our group! I'll try to answer any quake c questions - please post your inquiry in the forums...

Report article RSS Feed Compiler warnings and quake-c

How important are compiler warnings? With 2 code sets released to base mods on with the express purpose of being warning free, its time to exhort the importance of clearing out compiler warnings.

Posted by numbersix on Aug 24th, 2011
Article

The original quake-c v106 release had a few compiler warnings. Heck, get any open source or free code and compile it - chances are you will see some warnings.

Do they warrant attention or repair? That depends.
After all, the code compiles and runs. A cursory inspection may not even reveal any fault with it...

The most important question is - does anything break?

With quake-c you need to be aware that warnings can affect code operation - here is an example from the 1.06 code found in misc.qc:

misc.qc(201): warning: No operation performed

Code:

void() misc_fireball =
{
...
if (!self.speed)
self.speed == 1000; // *** this caused the warning
}

What should this code do?

A: if a misc_fireball entity is loaded on a map by this spawn function and no speed is set, a default of 1000 gets set.

What is wrong here?

A: "==" is a conditional test and not an assignment operator.

This code does NOT assign 1000 to self.speed!

To verify this - coded added to function to set a global we can check

float lastsp; // add above function
...
lastsp = self.speed; // put after assignment

Now load any map that has a misc_fireball with no set speed.
For this example I cheated with an additional code mod:

// if (!self.speed)

This does not rely on the map entity and always does the assignment.
NOTE: prvm_global is a darkplaces console command.

warning code:

]prvm_global server lastsp
lastsp: 350.0000

fixed code:

]prvm_global server lastsp
lastsp: 1000.0000

How does this code actually affect the game?

It turns out 350 - 700 is a much better fireball launch speed. 1000 is kind of fast. That may be why this compiler warning never got fixed.

This is just an example, however. If your quake-c has compiler warnings that could be why it is not performing as you expect. This exact conditional non assignment error has caused me headaches in the past. I fixed it easy because I always maintain my quake-c code warning free.

Post a Comment
click to sign in

You are not logged in, your comment will be anonymous unless you join the community today (totally free - or sign in with your social account on the right) which we encourage all contributors to do.

2000 characters limit; HTML formatting and smileys are not supported - text only

Established
Aug 18, 2011
Privacy
Public
Subscription
Open to all members
Homepage
Moddb.com
Contact
Send Message
Email
Members Only
Membership
Join this group
Group Watch
Track this group
Feature
Browse
Features
Report Abuse
Report article
Related Games
Quake
Quake Single & Multiplayer First Person Shooter
Related Engines
Quake Engine
Quake Engine GPL Released Jun 22, 1996
Related Groups
id Software
id Software Developer & Publisher
qc
qc Hardware & Tech group with 27 members