LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Finding the signedness of a variable. (https://www.linuxquestions.org/questions/linux-general-1/finding-the-signedness-of-a-variable-766700/)

jopu 11-04-2009 01:15 AM

Finding the signedness of a variable.
 
How do we find the signedness of a given variable.

Say,
int a; unsigned char b;
Pass it to a macro.
FindSign(a); //This should state it is signed.
FindSign(b); //This should state it is unsigned.

it should say if the variable is signed or unsigned.

evo2 11-04-2009 03:48 AM

Depends on the lanuage. For example in C++ you could simply do this by overloading the funtion. eg.

Code:

#include <iostream>
void FindSign( int i )
{
  std::cout << "Is signed" << std::endl;
}
void FindSign( unsigned int i )
{
  std::cout << "Is unsigned" << std::endl;
}
int main()
{
  int a = 1;
  unsigned int b = 1;
  FindSign(a);
  FindSign(b);
}



All times are GMT -5. The time now is 04:04 PM.