Unreachable code detected by using const variables
Posted
by
Anton Roth
on Stack Overflow
See other posts from Stack Overflow
or by Anton Roth
Published on 2013-07-01T10:15:25Z
Indexed on
2013/07/01
10:21 UTC
Read the original article
Hit count: 325
c#
|unreachable-code
I have following code:
private const FlyCapture2Managed.PixelFormat f7PF = FlyCapture2Managed.PixelFormat.PixelFormatMono16;
public PGRCamera(ExamForm input, bool red, int flags, int drawWidth, int drawHeight) {
if (f7PF == FlyCapture2Managed.PixelFormat.PixelFormatMono8) {
bpp = 8; // unreachable warning
}
else if (f7PF == FlyCapture2Managed.PixelFormat.PixelFormatMono16){
bpp = 16;
}
else {
MessageBox.Show("Camera misconfigured"); // unreachable warning
}
}
I understand that this code is unreachable, but I don't want that message to appear, since it's a configuration on compilation which just needs a change in the constant to test different settings, and the bits per pixel (bpp) change depending on the pixel format. Is there a good way to have just one variable being constant, deriving the other from it, but not resulting in an unreachable code warning? Note that I need both values, on start of the camera it needs to be configured to the proper Pixel Format, and my image understanding code needs to know how many bits the image is in.
So, is there a good workaround, or do I just live with this warning?
© Stack Overflow or respective owner