473,395 Members | 1,999 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Unused constants warnings.

Hi,

Is there a way for the compiler to warn about constants that are not used?
For example in the code below, could the compiler (with some sort of
attribute setting or something like that) throw an error or warning stating
that the DBParameters.Column2 isnt used?

Thanks,
Erik

__________________________________________________ __________________________
__________

public class DBParameters
{
public const string Column1 = "Column1";
public const string Column2 = "Column2"; // Throw a compiler error /
warning stating this isn't used.
public const string Column3 = "Column3";
}

public class Entity
{

int column1;
int column2;
int column3;

[DBParameter(Name = DBParameters.Column1)]
public int Column1
{
get { return m_column1; }
set { m_column1 = value; }
}

public int Column2
{
get { return m_column2; }
set { m_column2 = value; }
}

[DBParameter(Name = DBParameters.Column3)]
public int Column3
{
get { return m_column3; }
set { m_column3 = value; }
}
}
Nov 17 '05 #1
3 1905
No, there is no way the compiler can tell that the constant is not
used, because you've declared it "public." There is no way for the
compiler to know that some other code in some other assembly isn't
referencing this assembly and using that constant.

That said, it surprised me to find that the compiler doesn't complain
if you declare a private constant and then don't use it. It complains
for private fields, but not constants. How odd.

Nov 17 '05 #2
"Bruce Wood" <br*******@canada.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
No, there is no way the compiler can tell that the constant is not
used, because you've declared it "public." There is no way for the
compiler to know that some other code in some other assembly isn't
referencing this assembly and using that constant.

That said, it surprised me to find that the compiler doesn't complain
if you declare a private constant and then don't use it. It complains
for private fields, but not constants. How odd.
Makes sense, it would be a pain if it warned about unused constants.

Nov 17 '05 #3
> Makes sense, it would be a pain if it warned about unused constants.

Why? If you're not using something, why put it in the code? Remember,
we're talking about situations in which the constant really is unused:
it's private, so no other assembly and no other class can refer to it,
and the owning class doesn't use it. The compiler should issue a
warning so that you can delete the thing... it's not good for anything
other than confusing people reading the code. :)

Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: ralphNOSPAM | last post by:
Is there a PHP script that can find unused variables? I'd like to 'clean up' my scripts. Thanks...
15
by: Eirik | last post by:
This is a little function I wrote, inspired by the thread "Urgent HELP! required for Caesar Cipher PLEASE" $ cat /home/keisar/bin/c/ymse/rot13.h char rot13(char character) { int changed;...
11
by: Michael B Allen | last post by:
Is there a standard method for supressing warnings regarding unused parameters? I have a function that might be called hundreds of thousands of times that looks like this: const void *...
12
by: zacks | last post by:
Suddenly, in a VB2005 project I am working on, several variables show up in the list of warnings are being unused local variables. But they all are. Several of them are the ex variable used in a...
11
by: Charles Sullivan | last post by:
I have a number of functions, e.g.: int funct1( int arg1, int arg2, int arg3 ); int funct2( int arg1, int arg2, int arg3 ); int funct3( int arg1, int arg2, int arg3 ); that are called via...
8
by: Frank Rizzo | last post by:
Is there a setting in VS2005 to quickly locate methods that are unused (maybe through compiler warnings)? If not, any utilities out there that do that? Thanks
9
by: werasm | last post by:
Hi all, I'm looking for a nice clean (portable) way to get rid of unused variable warnings without fiddling with compiler settings (on a per case basis). I've come up with this: template...
33
by: jacob navia | last post by:
Hi I am considering extending the lcc-win32 compiler to accept int fn(int a, int b,double) { // body of the function } This allows the programmer to specify that the third parameter is not...
13
by: Rex Mottram | last post by:
I'm using an API which does a lot of callbacks. In classic callback style, each routine provides a void * pointer to carry user-defined data. Sometimes, however, the user-defined pointer is not...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.