473,385 Members | 1,615 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

what's the 'right' way to get rid of size_t to int conversion warnings?

Surely there is something clever to do here, besides turning off the
warning?

Glen
Mar 21 '06 #1
3 3791
glen stark wrote:
Surely there is something clever to do here, besides turning off the
warning?


Use size_t instead of int.

Or perhaps:

size_t size = 5;
int i = static_cast<int>(size);

Ben Pope
--
I'm not just a number. To many, I'm known as a string...
Mar 21 '06 #2
On Tue, 21 Mar 2006 17:22:06 +0100, glen stark <st***@ife.ee.ethz.ch>
wrote:
Surely there is something clever to do here, besides turning off the
warning?


Yes. Instead of writing this:
vector<something> v;
// fill the vector here...
for (int i=0; i<v.size(); ++i) /* ... */

write this:
for (size_t i=0; i<v.size(); ++i) /* ... */

Even better, use iterators.

--
Bob Hairgrove
No**********@Home.com
Mar 21 '06 #3

Bob Hairgrove wrote in message ...
On Tue, 21 Mar 2006 17:22:06 +0100, glen stark <st***@ife.ee.ethz.ch>
wrote:
Surely there is something clever to do here, besides turning off the
warning?


Yes. Instead of writing this:
vector<something> v;
// fill the vector here...
for (int i=0; i<v.size(); ++i) /* ... */

write this:
for (size_t i=0; i<v.size(); ++i) /* ... */

Even better, use iterators.
Bob Hairgrove


OP: Another 'clunky' way to do it:

std::string String("Good");

// for( int i(0); i < String.size(); ++i ){
// [Warning] comparison between signed and unsigned integer expressions

for( int i(0); size_t( i ) < String.size(); ++i ){
std::cout<<"String.at(" << i << ")="<<String.at( i )<<std::endl;
}

--
Bob R
POVrookie
Mar 21 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: spasmous | last post by:
I'm getting an error when using a C program that accepts **float as arguments in my C++ code. Here the code (short): float A = {0,0,0,1,2,0,3,4,0}; float W = {0,0,0}; float V =...
17
by: candy_init | last post by:
I sometimes comes across statements which invloves the use of size_t.But I dont know exactly that what is the meaning of size_t.What I know about it is that it is used to hide the platform...
25
by: Joakim Hove | last post by:
Hello, I have code which makses use of variables of type size_t. The code is originally developed on a 32 bit machine, but now it is run on both a 32 bit and a 64 bit machine. In the code...
11
by: Alfonso Morra | last post by:
Hi, I am at the end of my tether now - after spending several days trying to figure how to do this. I have finally written a simple "proof of concept" program to test serializing a structure...
9
by: Notebooker | last post by:
Hello, I'm an intermediate noob reading-in data from ascii-file using an ifstream object. I have specified a c-style string buffer with size of type size_t and I am specifying to use this...
30
by: Bill Reid | last post by:
#define MAX_VALUES 64 typedef struct { unsigned value_1; double value_2; double value_3; double value_4; } VALUES; typedef struct {
25
by: =?Utf-8?B?R2Vvcmdl?= | last post by:
Hello everyone, When converting from size_t to unsigned int, there will be a warning message, warning C4267: '=' : conversion from 'size_t' to 'int', possible loss of data I do not know...
409
by: jacob navia | last post by:
I am trying to compile as much code in 64 bit mode as possible to test the 64 bit version of lcc-win. The problem appears now that size_t is now 64 bits. Fine. It has to be since there are...
89
by: Tubular Technician | last post by:
Hello, World! Reading this group for some time I came to the conclusion that people here are split into several fractions regarding size_t, including, but not limited to, * size_t is the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
Oralloy
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,...
0
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...

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.