473,511 Members | 17,486 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Optimization: Comparing Signed with Unsigned

2 New Member
Hello everyone,

I am trying to optimize an application and while I was working on that I stumbled upon a question that I can't really find an answer for.

I was wondering whether there was a performance penalty for comparing Signed variables against Unsigned variables, such as displayed below in this post.
I have a lot of memory to play with so increased memory usage is alright for me, so if there is a performance hit (even a nano second) then I'd rather exchange them with a bigger signed indentifier (I require the negative values).

hmm, this also creates the question as whether Signed or Unsigned variables are faster if used exclusively...

For example:
Expand|Select|Wrap|Line Numbers
  1. unsigned char variable_a = 5;
  2. short variable_b = 5;
  3.  
  4. if(variable_a > variable_b) // < >= <= == whatever
  5. {
  6.      //bla
  7. }
  8.  
If anyone knowns I would love to hear :)
Sep 4 '07 #1
2 1925
weaknessforcats
9,208 Recognized Expert Moderator Expert
The larger issue is whether your data values can be negative. If so, you must use an int.

Otherwise, just use an unsigned int.

The comparison is irrelevant.
Sep 5 '07 #2
Lugard
2 New Member
edit: sorry, need to give this some thought (posted by accident, couldn't figure out how to remove)
Sep 5 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
3444
by: Zach | last post by:
What happens when you compare a char against an integer literal? For example, #include <iostream> using namespace std; int main(int argc, char* argv) { signed char c1 = 150; if (c1 < 150)...
6
5142
by: Christopher Benson-Manica | last post by:
int main() { bool foo=false; for( unsigned int bar=0; bar < (foo?1:2); bar++ ) { bar=42; } return 0; } A certain C++ compiler I am using claims that there exists in the
16
2788
by: Kevin Goodsell | last post by:
What do you think is the best way to handle a compiler warning about comparing an unsigned value to a signed value? Cast to silence it? Disable that warning altogether? Or just live with it? On...
88
21950
by: William Krick | last post by:
I'm currently evaluating two implementations of a case insensitive string comparison function to replace the non-ANSI stricmp(). Both of the implementations below seem to work fine but I'm...
3
3830
by: Joe Van Dyk | last post by:
What bad things could happen if I compare signed and unsigned integers? (is that even valid C?) Thanks, Joe
10
3282
by: =?iso-8859-2?B?SmFuIFJpbmdvuQ==?= | last post by:
Hello everybody, this is my first post to a newsgroup at all. I would like to get some feedback on one proposal I am thinking about: --- begin of proposal --- Proposal to add...
7
1765
by: Nevil Lesdog | last post by:
What do you think is the best way to handle a compiler warning about comparing an unsinged value to a singed value? Cast to silence it? Disable that warning altogether? Or just live with it? On...
6
6427
by: Kislay | last post by:
Consider the following code snippet unsigned int i=10; int j= - 2; // minus 2 if(i>j) cout<<"i is greater"; else cout<<"j is greater"; Since i is unsigned , j is greater . I know why , but...
13
2706
by: Andreas Eibach | last post by:
Hi, let's say I have this: #include <string.h> #define BLAH "foo" Later on, I do this:
0
7245
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7144
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
7427
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7085
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
7512
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...
1
5069
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3227
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1577
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
785
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.