Hello!
In my program I need to compare a long variable with a size_t variable. The
long variable's value is guaranteed to be positive since it's initialised by
a function returning a positive value (or -1L when an error occurs, which I
check for). When I compare these variables with >, I get the warning
"comparison between signed and unsigned". Given that the long variable is
guaranteed to hold a positive value, can I ignore this diagnostic or should
I deal with it in some way?
BTW, I'm having endless trouble getting the hang of C. I can't quite
understand it because I tend to grasp languages pretty quickly. How long
does it take for C to truly 'click'?
---
JB 2 4955
On Thu, 23 Oct 2003 16:26:10 +0100, John Buckley wrote: Hello!
In my program I need to compare a long variable with a size_t variable. The long variable's value is guaranteed to be positive since it's initialised by a function returning a positive value (or -1L when an error occurs, which I check for). When I compare these variables with >, I get the warning "comparison between signed and unsigned". Given that the long variable is guaranteed to hold a positive value, can I ignore this diagnostic or should I deal with it in some way?
There was a thread recently talking about this. The message ID of the
first post was
<mI************ *****@newsread3 .news.pas.earth link.net>
In <bn**********@n ewsg2.svr.pol.c o.uk> "John Buckley" <us**@example.n et> writes: In my program I need to compare a long variable with a size_t variable. The long variable's value is guaranteed to be positive since it's initialised by a function returning a positive value (or -1L when an error occurs, which I check for). When I compare these variables with >, I get the warning "comparison between signed and unsigned". Given that the long variable is guaranteed to hold a positive value, can I ignore this diagnostic or should I deal with it in some way?
The best thing to do, if you trust your C skills, is to disable (or not
enable) this warning. Most of the time (or all the time if you know what
you're doing) it is merely a source of noise. gcc -Wall, for example,
does not enable such warnings, leaving them for the masochists who also
use -W.
BTW, I'm having endless trouble getting the hang of C. I can't quite understand it because I tend to grasp languages pretty quickly. How long does it take for C to truly 'click'?
It depends on how much time you spend trying to understand the language,
rather than playing with it. After reading K&R2 and the c.l.c FAQ, you
should have a fairly clear idea about the language, including most of the
darker spots.
Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: g |
last post by:
Hi all.
Maybe this question has been asked many times before, but I was not able to find
any pointer. I apologize in advance, for it refers to a particular standard
library implementation (GNU C++ version 3.x), but perhaps it's more general than
that.
The following program (to be compiled with g++ 3.x, 2.9x is not enough)
#include <iostream>
#include <string>
|
by: Paul Edwards |
last post by:
I have the following C program:
#include <stdio.h>
int main(void)
{
unsigned short x = 32768, y=16384;
if (x > y)
{
|
by: Alex |
last post by:
I have a problem about the comparison between signed and unsigned
integer.
See the following code:
int foo()
{
int i;
unsigned int j;
if (i < j)
{
|
by: Timothee Groleau |
last post by:
Hi all,
When should I be worried about doing a comparison of signed vs unsigned
ints? Could someone give me a example where such a comparison would lead to
unwanted results?
Thanks,
Tim.
|
by: Frederick Gotham |
last post by:
I just want to clarify my understanding of arithmetic and comparison
between two different integer types.
Phase (1): Integer Promotion
----------
All of the following types always get promoted to "signed int":
signed char
| |
by: Gary Wessle |
last post by:
Hi
I am writing a code to open a space delimited data file, return the
number of rows and columns, as well as return the nth column where n
is user define number.
I put all the cells in a loooong vector and loop in an incremental way
to select the column of choice, here is the code which works but gives
a warning
****************************************************************
|
by: John Ratliff |
last post by:
"comparison is always false due to limited range of data type"
I get this warning with g++ when I compile some code and I'm not quite
sure I understand it.
I have a small file that I've read into a memory buffer. It is defined
char sram;
I need to check for a specific value within this buffer.
|
by: Mosfet |
last post by:
Hi,
what is the most efficient way of doing a case insensitive comparison ?
I am trying to write a universal String class and I am stuck with the
case insensitive part :
TCHAR is a char in MultiByte String env (MBCS)
and wchar_t if UNICODE
#if defined(WIN32) || defined(UNDER_CE)
|
by: compcreator |
last post by:
I have tried the following program. The problem is it is printing
False
I checked values for a and b but there is something wrong with the
comparison.
I thing it might be because of signed and unsigned conversion.
Either b is upgraded to unsigned and the resulting value during
comparison is 5 or a is downgraded to signed and the resulting value
is lower than -1.
|
by: evanevankan2 |
last post by:
I have a question about the warning 'comparison between signed and
unsigned' I get from my code. It comes from the conditional in the
outer for loop.
I understand the warning, but I'm not sure what is the best way to
prevent it. I can just change i to a type size_t or maybe put a cast
in the conditional, but I don't know which way that is 'best'?
Any ideas? I provided the code below for some context.
And while we're at it, could you...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 we have to send another system
| |