Setting to disable "unused variable" warnings in e

Archive of the older Feature Request Forum Posts

Moderator: POL Developer

Locked
Yukiko
Distro Developer
Posts: 2825
Joined: Thu Feb 02, 2006 1:41 pm

Setting to disable "unused variable" warnings in e

Post by Yukiko »

Yeah it's a small thing but I like to see clean compiles and many times those "unused" variables are used simply because they get assigned a value.

Anyway can you please give us a setting in eCompile.cfg for this.

Also, if you could address the case 'default' issue I posted about too.
Marilla

Post by Marilla »

Why do you need to create a variable only to assign a value to it, if you aren't going to use the value? And for that matter, doesn't assigning a value to a variable count as it being used? Isn't it only when you have a function parameter or a declared local var that you never use at all that this warning comes?

The biggest time this happens to me is with standard scripts for things like dot-commands or UseScripts, where the basic parameters are not used in the script; For instance, a dot-command that does not need to use the Char Ref or Text values; I prefer leaving the parameters defined just in case I might need them in the future (yes, I know it'd be easy as pie to add them back!), and I don't like doing the "who:=who;" trick)

Erm... with all that said; I have to agree that an ecompile.cfg option for this would be nice, to address the issue I note above. Of course, I'll live without it, but if it's an easy option to add, it'd be nice, indeed!!
Lagoon
Grandmaster Poster
Posts: 118
Joined: Sun Mar 05, 2006 7:25 am

Post by Lagoon »

I think there's a better solution to avoid the spam of unused variables in textcommands and similar scripts. Actually the "trick" is to do something like

unused_var :_= unused_var;

This avoids the warning, but adds unnecessary code. Imho it would be cool to add some instruction which is used to tell the compiler "I know I'm not using that variable, please don't print warning", something like

NOUSE unused_var;
or
nouse(unused_var);

which isn't really translated in istructions
Yukiko
Distro Developer
Posts: 2825
Joined: Thu Feb 02, 2006 1:41 pm

Post by Yukiko »

An eCompile option would be the most efficient alternative and it shouldn't be that hard to code into eCompile.

I see no reason why I, or anyone else for that matter, should have to create a special line of code in my scripts (or add one to other scripts (including the Distro code)) to stop the warnings.

I gather the warnings are there to promote optimized code but there are times when a variable is declared because it has to be but never gets "used" the way eCompile defines being used. See Marilla's post as an example.
User avatar
CWO
POL Expert
Posts: 1159
Joined: Sat Feb 04, 2006 5:49 pm

Post by CWO »

maybe just need to make ecompile ignore variables declared in the program params? This would solve everyone's problems wouldnt it?
Marilla

Post by Marilla »

No; I think it should be an option, if it's changed. I would still want to be aware of unused variables, including function/'program' parameters. Most of the time, they would be used for something, or could really be left out.
Yukiko
Distro Developer
Posts: 2825
Joined: Thu Feb 02, 2006 1:41 pm

Post by Yukiko »

Actually CWO the answer to your question is "No".

Note the following from POL 96/97 Distro spellStarter.src found in \Distro\pkg\skills\magery:

Code: Select all

program SpellStarter(params)
	var mobile := params[1]; // Caster
	var spell_id := params[2]; // Id # of the spell
	var scroll := params[3]; // Scroll object being used
	var targ := params[4]; // NPC target //This line generates an "unused" warning and targ is definitely used here.
...
The option cfg option is the best way to go.
Marilla

Post by Marilla »

Yukiko wrote:

Code: Select all

program SpellStarter(params)
	var mobile := params[1]; // Caster
	var spell_id := params[2]; // Id # of the spell
	var scroll := params[3]; // Scroll object being used
	var targ := params[4]; // NPC target //This line generates an "unused" warning and targ is definitely used here.
...
Why would that line generate a warning, but the rest don't? If that's the case, sounds to me like there's just a bug in the reporting that needs to be fixed; a bug which adding this option (which I otherwise support) would just cover up.
User avatar
CWO
POL Expert
Posts: 1159
Joined: Sat Feb 04, 2006 5:49 pm

Post by CWO »

ya I wasnt saying ignore as in never being able to use them ever... I meant to not throw a warning when a program's params arent used.
DeiviD
Expert Poster
Posts: 79
Joined: Mon Jun 19, 2006 4:48 pm

Post by DeiviD »

i like the ideia really

oninserts and similar scripts have a load of (usually unused) params

plus sometimes you leave an unused var or two for future use or stuff like that

and who:=who sux, is useless and wastes cpu cicles :P
User avatar
CWO
POL Expert
Posts: 1159
Joined: Sat Feb 04, 2006 5:49 pm

Post by CWO »

I was just looking over this topic yesterday too thinking maybe we got an answer and I just missed it.

Now rewriting my scriptbase I've severely slashed the number of instructions my shard's scripts do (and still going) and I instated a "No compile warnings" policy for the other shard devs but its hard to enforce that with these things and still say, dont do anything thats not truely needed... its either one or the other...
Locked