LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 11-04-2009, 01:15 AM   #1
jopu
LQ Newbie
 
Registered: Mar 2007
Posts: 8

Rep: Reputation: 0
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.
 
Old 11-04-2009, 03:48 AM   #2
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
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);
}
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
AWK a variable Ouptut to a new variable and using the new variable with the old one alertroshannow Linux - Newbie 4 02-16-2009 12:08 AM
Sed search for variable and delete entire line, but variable contains forward /'s Passions Programming 2 11-10-2008 03:44 PM
differ in signedness error rzarector Programming 6 10-02-2006 01:05 PM
About pointer signedness warnings isuck@linux Linux - Software 2 08-26-2006 07:18 PM
setting a variable variable in a script... this works, but could it be more elegant? pwc101 Programming 3 08-18-2006 11:23 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 10:50 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration