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 why, since in crtdbg.h, size_t is defined to int, right?
thanks in advance,
George 25 11677
"George" wrote:
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 why, since in crtdbg.h, size_t is defined to int, right?
No, it is defined to unsigned int. And you are not converting from size_t to
unsigned int, otherwise the warning message wouldn't come up.
best
doc
Hi doc,
I am using VS 2003. I find that even if I convert to unsigned int, the error
message is the same.
Do you know the reason?
regards,
George
"docschnipp " wrote:
"George" wrote:
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 why, since in crtdbg.h, size_t is defined to int, right?
No, it is defined to unsigned int. And you are not converting from size_t to
unsigned int, otherwise the warning message wouldn't come up.
best
doc
George wrote:
:: Hi doc,
::
::
:: I am using VS 2003. I find that even if I convert to unsigned int,
:: the error message is the same.
::
:: Do you know the reason?
1) It is a compatibility warning, because size_t doesn't have to be
the same size on all systems. Particularly, for 64 bit compiles it is
different from a 32 bit compile. http://msdn2.microsoft.com/en-us/lib...93(VS.80).aspx
2) Why do you want to do this in the first place? Why not use a size_t
variable?
Bo Persson
::
::
:: regards,
:: George
::
:: "docschnipp " wrote:
::
::: "George" wrote:
:::
:::: 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 why, since in crtdbg.h, size_t is defined to int,
:::: right?
:::
::: No, it is defined to unsigned int. And you are not converting
::: from size_t to unsigned int, otherwise the warning message
::: wouldn't come up.
:::
::: best
::: doc
George wrote:
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 why, since in crtdbg.h, size_t is defined to int, right?
George:
No, In Win32 size_t is unsigned int. The error message says size_t to
int (not size_t to unsigned int as in your question).
In Win64 (or with Win64 warnings turned on), you will get a warning for
converting size_t to unsigned int, because in Win64 size_t is an
unsigned 64-bit value.
Just use an explicit cast. Although I use C++ casts in other contexts,
for simple integer conversions I normally use C-style cast:
size_t n1 = 12345;
int n2 = (int)n1;
--
David Wilkinson
Visual C++ MVP
"Bo Persson" wrote:
>
2) Why do you want to do this in the first place? Why not use a size_t
variable?
I guess the reason is as usual: using several pieces of code, one is using
size_t, others, not originating the Windows platform, use int or unsigned
int.
best
doc
Hi,
I am using 32-bit machine. I need to pass the size_t to another function
which accepts unsigned int.
I think it is ok to pass size_t to unsigned int, but I do not know why there
is warning.
regards,
George
"Bo Persson" wrote:
George wrote:
:: Hi doc,
::
::
:: I am using VS 2003. I find that even if I convert to unsigned int,
:: the error message is the same.
::
:: Do you know the reason?
1) It is a compatibility warning, because size_t doesn't have to be
the same size on all systems. Particularly, for 64 bit compiles it is
different from a 32 bit compile.
http://msdn2.microsoft.com/en-us/lib...93(VS.80).aspx
2) Why do you want to do this in the first place? Why not use a size_t
variable?
Bo Persson
::
::
:: regards,
:: George
::
:: "docschnipp " wrote:
::
::: "George" wrote:
:::
:::: 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 why, since in crtdbg.h, size_t is defined to int,
:::: right?
:::
::: No, it is defined to unsigned int. And you are not converting
::: from size_t to unsigned int, otherwise the warning message
::: wouldn't come up.
:::
::: best
::: doc
Hi doc,
I do not know why in Visual Studio 2003, there is warning message when
converting from size_t to unsigned int. I think they are the same?
Any ideas?
regards,
George
"docschnipp " wrote:
"Bo Persson" wrote:
2) Why do you want to do this in the first place? Why not use a size_t
variable?
I guess the reason is as usual: using several pieces of code, one is using
size_t, others, not originating the Windows platform, use int or unsigned
int.
best
doc
Hi David,
When converting from size_t to unsigned int, there are still warning message
in Visual Studio 2003. You can have a try. I have no idea why converting to
unsigned int has warning information.
regards,
George
"David Wilkinson" wrote:
George wrote:
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 why, since in crtdbg.h, size_t is defined to int, right?
George:
No, In Win32 size_t is unsigned int. The error message says size_t to
int (not size_t to unsigned int as in your question).
In Win64 (or with Win64 warnings turned on), you will get a warning for
converting size_t to unsigned int, because in Win64 size_t is an
unsigned 64-bit value.
Just use an explicit cast. Although I use C++ casts in other contexts,
for simple integer conversions I normally use C-style cast:
size_t n1 = 12345;
int n2 = (int)n1;
--
David Wilkinson
Visual C++ MVP
George wrote:
Hi David,
When converting from size_t to unsigned int, there are still warning message
in Visual Studio 2003. You can have a try. I have no idea why converting to
unsigned int has warning information.
regards,
George
"David Wilkinson" wrote:
>George wrote:
>>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 why, since in crtdbg.h, size_t is defined to int, right?
George:
No, In Win32 size_t is unsigned int. The error message says size_t to int (not size_t to unsigned int as in your question).
In Win64 (or with Win64 warnings turned on), you will get a warning for converting size_t to unsigned int, because in Win64 size_t is an unsigned 64-bit value.
Just use an explicit cast. Although I use C++ casts in other contexts, for simple integer conversions I normally use C-style cast:
size_t n1 = 12345; int n2 = (int)n1;
-- David Wilkinson Visual C++ MVP
George:
Maybe you have 64-bit warnings turned on (a good idea, in my opinion).
Look in project properties under
Configuration Properties -C/C++ -General.
--
David Wilkinson
Visual C++ MVP This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Sam Smith |
last post by:
Hi,
I wan't a function to take a const char*, a start bit position and number of
bits and convert that bit-stream into a primitive of desired type.
I.e. something like:
char convert(const unsigned char* buffer, size_t start_pos, size_t length)
{
char value = 0;
|
by: William Xuuu |
last post by:
Hi,
This's a way of defining size_t and ssize_t in Linux:
//"linux/types.h"
typedef __kernel_size_t size_t;
typedef __kernel_ssize_t ssize_t;
//"asm/posix_types.h"
typedef unsigned int __kernel_size_t;
|
by: sposes |
last post by:
Im very much a newbie but perhaps somehone can help me. Ive been
searching for a way to convert a std::string to a unsigned char*
The situation is I have a function that wants a unsigned char* and I
want to give it a std::string
no matching function for call to `MD5::update(std::string&, size_t)'
candidates are: void MD5::update(unsigned char*, unsigned int)
void PrintMD5(string str){
|
by: bwaichu |
last post by:
To avoid padding in structures, where is the best place to put size_t
variables?
According the faq question 2.12 (http://c-faq.com/struct/padding.html),
it says:
"If you're worried about wasted space, you can minimize the effects of
padding by ordering the members of a structure based on their base
types, from largest to smallest."
|
by: subramanian100in |
last post by:
Consider the following program
#include <limits.h>
#include <stddef.h>
int main(void)
{
size_t size;
size_t bytes = sizeof(size_t);
| |
by: Paulo Matos |
last post by:
Hello,
Is it safe to assume a size_t is an unsigned long? (is it forced by
the standard?)
Thank you,
Paulo Matos
|
by: lubomir dobsik |
last post by:
hi, i have seen an interesting thing:
#if sizeof((char*)0 - (char*)0) == sizeof(unsigned int)
typedef unsigned int size_t;
#elif sizeof((char*)0 - (char*)0) == sizeof(unsigned long)
typedef unsigned long size_t;
#elif sizeof((char*)0 - (char*)0) == sizeof(unsigned long long)
typedef unsigned long long size_t;
#endif
|
by: Juha Nieminen |
last post by:
Unknownmat wrote:
VS2005 has a bug related to this. When you use size_t, it internally
converts it to 'unsigned int'. In some situations it forgets that the
type was actually size_t and only sees it's an 'unsigned int', so when
you eg. assign a size_t value to such a "unsigned int which was a size_t
but VS2005 has forgotten about it", it will give you a warning about
possible data loss (because it only sees that a size_t is being...
|
by: Alex Vinokur |
last post by:
Hi,
Is it possible to do C++-casting from
const pair<const unsigned char*, size_t>*
to
const pair<unsigned char*, size_t>*
?
Alex Vinokur
|
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: 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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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: 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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |