473,395 Members | 1,870 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,395 software developers and data experts.

Re: Unexpected compiler behavior relating to size_t and boost - VisualStudio 2005.

Unknownmat wrote:
I am using Visual Studio 2005 (msvc 8.0, I believe). I am experience
some unexpected compiler warnings that have to do with how integer
types, size_t, and boost interact.
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 assigned
to an unsigned int, and this triggers its warning about possible loss of
data, as size_t may be bigger than unsigned int in another system).

I don't know if anything can be done about that, except turning the
warning off. (You can turn it off on a per-file basis using a #pragma.)
Jul 14 '08 #1
4 1826
On Jul 14, 4:51 pm, Juha Nieminen <nos...@thanks.invalidwrote:
Unknownmat wrote:
I am using Visual Studio 2005 (msvc 8.0, I believe). I am experience
some unexpected compiler warnings that have to do with how integer
types, size_t, and boost interact.
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',
How is that a bug? size_t is required to be a typedef, not a
real type, and on a lot of 32 bit machines, it is an unsigned
int. Not "gets converted to", but "is".

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Jul 14 '08 #2
Juha Nieminen wrote:
Unknownmat wrote:
I am using Visual Studio 2005 (msvc 8.0, I believe). I am experience
some unexpected compiler warnings that have to do with how integer
types, size_t, and boost interact.

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 assigned
to an unsigned int, and this triggers its warning about possible loss of
data, as size_t may be bigger than unsigned int in another system).

I don't know if anything can be done about that, except turning the
warning off. (You can turn it off on a per-file basis using a #pragma.)
Thanks for the response that helps immensley. Do you happen to have a
Microsoft KB link?

I will do some more digging now that I know that this is VS2005
related. What's interesting to me is that I am very careful about
using size_t - I never need to typecast between unsigned and size_t
(unless I'm forced to by a library API or something). In the example
I posted above, in fact, I'm not even USING the vector< size_tobject
- there's simply no way this object could cause a conversion error.

Thanks,
Matt
Jul 14 '08 #3
Unknownmat wrote:
What's interesting to me is that I am very careful about
using size_t - I never need to typecast between unsigned and size_t
(unless I'm forced to by a library API or something). In the example
I posted above, in fact, I'm not even USING the vector< size_tobject
- there's simply no way this object could cause a conversion error.
That's the funny side-effect of that bug: Even if there isn't even a
single "int" or "unsigned int" in the entire program, only size_t (and
some template, which is what usually causes the problem), the compiler
will still trigger a warning about an inexistent "unsigned int".

(The problem is understandable because when compiling a 32-bit program
size_t *is* an unsigned int, but other compilers are able to retain the
info that it was, actually, a size_t all the way and they don't give any
warnings.)
Jul 14 '08 #4
On Jul 14, 7:42 pm, Juha Nieminen <nos...@thanks.invalidwrote:
Unknownmat wrote:
What's interesting to me is that I am very careful about
using size_t - I never need to typecast between unsigned and size_t
(unless I'm forced to by a library API or something). In the example
I posted above, in fact, I'm not even USING the vector< size_tobject
- there's simply no way this object could cause a conversion error.
That's the funny side-effect of that bug: Even if there isn't
even a single "int" or "unsigned int" in the entire program,
only size_t (and some template, which is what usually causes
the problem), the compiler will still trigger a warning about
an inexistent "unsigned int".
(The problem is understandable because when compiling a 32-bit
program size_t *is* an unsigned int, but other compilers are
able to retain the info that it was, actually, a size_t all
the way and they don't give any warnings.)
I think you have it backwards. Other compilers simply consider
it an unsigned int (or whatever), and get on with it; they don't
try to treat size_t differently from whatever it is typedef'ed
to.

Which is, of course, what the standard says the compiler should
do.

Of course, there's nothing wrong with keeping the fact that this
unsigned int was originally a size_t, for things like error
messages, e.g. displaying std::vector< size_t ... instead of
std::vector< unsigned int ... >. But in practice, most don't
seem to: if I write:
std::vector< std::size_t v ;
v.push_back( 1, 2 ) ;
both g++ and Sun CC complain about an error using a member
function of "std::vector<unsigned int, std::allocator<unsigned
int" (g++) or "std::vector<unsigned>" (Sun CC). Only VC++
retains this information, displaying an error in
"std::vector<_Ty>", but later indicating that _Ty=size_t (which
is actually pretty nice---it's nice, too, that both Sun CC and
VC++ omit mentionning the allocator).

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Jul 15 '08 #5

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

Similar topics

19
by: Canonical Latin | last post by:
"Leor Zolman" <leor@bdsoft.com> wrote > "Canonical Latin" <javaplus@hotmail.com> wrote: > > > ... > >But I'm still curious as to the rational of having type >...
62
by: ashu | last post by:
hi look at this code include <stdio.h> int main(void) { int i,j=2; i=j++ * ++j * j++; printf("%d %d",i,j); return 0;
33
by: Geometer | last post by:
Hello, and good whatever daytime is at your place.. please can somebody tell me, what the standard behavior of strtok shall be, if it encounters two or more consecutive delimiters like in...
11
by: Osiris | last post by:
I have these pieces of C-code (NOT C++ !!) I want to call from Python. I found Boost. I have MS Visual Studio 2005 with C++. is this the idea: I write the following C source file:...
0
by: Osiris | last post by:
I read a lot of the html pages on installing boost etc. Still a lot of confusion. Here is what I want: I have old, stable wonderful C-code I want to use in Python projects. So I encapsulate the...
3
Axon
by: Axon | last post by:
Hi, I'm using Boost::uBLAS::mapped_matrix for working with sparse matrices. At the moment, the maximum dimension of mapped_matrix is 65535x65535 since std::size_t compiles as unsigned int. I'm...
2
by: Dimitri Furman | last post by:
SQL Server 2000 SP4. Running the script below prints 'Unexpected': ----------------------------- DECLARE @String AS varchar(1) SELECT @String = 'z' IF @String LIKE ''
2
by: atishrg | last post by:
Hello All Need your help.. I created addin for outlook 2007 in vs2005(vb.net)... It is working fine now I Migrated that to vs2008 and created setup for that in vs2008...
3
by: Unknownmat | last post by:
Here is the smallest code I could come up with to reproduce the I was able to reproduce the warning with an even smaller snippet of code: #include <vector> #include <functional> #include...
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
0
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
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...
0
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
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...

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.