Why are long integers inappropriate for switch expressions?
Why are long integers used in switch expressions (C99) flagged as a defect for being an inappropriate data type in Polyspace Bug Finder?
Matlab documentation only allows char, int, short or enum. Considering int can be either a 64 or 32 bit integer dependent on platform, it seems that a long, an explicit 32 bit integer, should be allowed.
Link to Matlab documentation of defect:
https://www.mathworks.com/help/bugfinder/ref/possiblyinappropriatedatatypeforswitchexpression.html
Example:
unsigned long x = 1u;
switch(x) // Defect
{
case 0u:
// do thing
break;
default:
// do thing
break;
}
unsigned int y = 1u;
switch(y) // No defect
{
case 0u:
// do thing
break;
default:
// do thing
break;
}
Thanks,
TommyWhy are long integers used in switch expressions (C99) flagged as a defect for being an inappropriate data type in Polyspace Bug Finder?
Matlab documentation only allows char, int, short or enum. Considering int can be either a 64 or 32 bit integer dependent on platform, it seems that a long, an explicit 32 bit integer, should be allowed.
Link to Matlab documentation of defect:
https://www.mathworks.com/help/bugfinder/ref/possiblyinappropriatedatatypeforswitchexpression.html
Example:
unsigned long x = 1u;
switch(x) // Defect
{
case 0u:
// do thing
break;
default:
// do thing
break;
}
unsigned int y = 1u;
switch(y) // No defect
{
case 0u:
// do thing
break;
default:
// do thing
break;
}
Thanks,
Tommy Why are long integers used in switch expressions (C99) flagged as a defect for being an inappropriate data type in Polyspace Bug Finder?
Matlab documentation only allows char, int, short or enum. Considering int can be either a 64 or 32 bit integer dependent on platform, it seems that a long, an explicit 32 bit integer, should be allowed.
Link to Matlab documentation of defect:
https://www.mathworks.com/help/bugfinder/ref/possiblyinappropriatedatatypeforswitchexpression.html
Example:
unsigned long x = 1u;
switch(x) // Defect
{
case 0u:
// do thing
break;
default:
// do thing
break;
}
unsigned int y = 1u;
switch(y) // No defect
{
case 0u:
// do thing
break;
default:
// do thing
break;
}
Thanks,
Tommy polyspace, switch expression, data type, c99 MATLAB Answers — New Questions