"Variable/Constant/.etc never used" warning

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Phantomas
User
User
Posts: 96
Joined: Wed Jul 01, 2009 12:59 pm

"Variable/Constant/.etc never used" warning

Post by Phantomas »

Hello. I am surprised why it isn't exists yet!

Code: Select all

EnableExplicit
#constant = 0
Define int.i = 1
Define string.s = "hello"
Dim arr.s(4)
string = "hi"
Like that:
Warning: constant "#constant" is assigned but never used!
Warning: variable "int" (Integer) is assigned but never used!
Warning: variable "arr" (String, Array) is assigned but never used!
http://www.west-wind.com/Weblog/images/ ... a38576.png
http://d2o0t5hpnwv4c1.cloudfront.net/10 ... riable.png
User avatar
leonhardt
Enthusiast
Enthusiast
Posts: 220
Joined: Wed Dec 23, 2009 3:26 pm

Re: "Variable/Constant/.etc never used" warning

Post by leonhardt »

like Delphi compiler :D
poor English...

PureBasic & Delphi & VBA
Deluxe0321
User
User
Posts: 69
Joined: Tue Sep 16, 2008 6:11 am
Location: ger

Re: "Variable/Constant/.etc never used" warning

Post by Deluxe0321 »

Good idea for variables, but not for constans..

Think about the include files for libs etc. it would be annoying to see 2k 'Warning: constant "#constant" is assigned but never used!' messages.
Unsued constants could be execluded from the ASM output (if not done allready?) - to save memory :D
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: "Variable/Constant/.etc never used" warning

Post by Danilo »

Constants are like macro replacements. This is the same:

Code: Select all

#CONSTANT      = 12
Macro CONSTANT : 12 : EndMacro
Not used, nothing is included. Used, the value is inserted. (x = #CONSTANT and x = CONSTANT become both x = 12)

Other languages have const variables. Variables that are not write-able after assignment (you can read them and you can get a pointer to const variables).
This is not the same as PB constants.
Deluxe0321
User
User
Posts: 69
Joined: Tue Sep 16, 2008 6:11 am
Location: ger

Re: "Variable/Constant/.etc never used" warning

Post by Deluxe0321 »

Thank you Danilo for making that clear.
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Re: "Variable/Constant/.etc never used" warning

Post by Joakim Christiansen »

Would be nice, but may also come with an option to turn it off.
I like logic, hence I dislike humans but love computers.
User avatar
Josh
Addict
Addict
Posts: 1183
Joined: Sat Feb 13, 2010 3:45 pm

Re: "Variable/Constant/.etc never used" warning

Post by Josh »

Yes, would be a nice feature. For me it would be enough, checked only when I start Compiler/SyntaxCheck
sorry for my bad english
Post Reply