The Nightstar Zoo

Nightstar IRC Network - irc.nightstar.net
It is currently Fri Dec 15, 2017 5:10 am

All times are UTC - 6 hours [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Wed Jul 14, 2004 12:25 pm 
Offline
Energizer Bunny
User avatar

Joined: Wed May 22, 2002 12:24 am
Posts: 1634
Things that compiler do that make you go "hmm..."

h:\Geodesate\main.cpp(40) : warning C4267: 'argument' : conversion from 'size_t' to 'unsigned int', possible loss of data

out_file << " " << geodesation.sideToSize(size * 3 + 1);

Why does VS.NET not have a standard operator<<(ostream&, size_t)?

Vorn


Top
 Profile  
 
PostPosted: Wed Jul 14, 2004 12:53 pm 
Vorn the Unspeakable wrote:
Things that compiler do that make you go "hmm..."

h:\Geodesate\main.cpp(40) : warning C4267: 'argument' : conversion from 'size_t' to 'unsigned int', possible loss of data

Don't jump so soon to call that stupid. On a 64-bit platform (at least under Windows - no idea about other platforms), size_t is 64 bits and int is 32 bits. There would be a loss of data, if you were playing with sizes over 4Gb.

Unlikely, yeah, but the compiler likes to deal in sureties, not likelihoods.

Vorn the Unspeakable wrote:
out_file << " " << geodesation.sideToSize(size * 3 + 1);

Why does VS.NET not have a standard operator<<(ostream&, size_t)?

Complain to the folks who wrote the STL.

Anyways, in VS, you can cast to an INT_PTR without any loss of data (or warnings). That compiles to an integer the same size as a pointer.

If you don't care about loss of data (or intend never to compile on a 64-bit OS), you can either just ignore it because it's only a warning, or static_cast<int>(your_size_t_var) to explicitly coerce it into the type you like.


Top
  
 
PostPosted: Wed Jul 14, 2004 1:20 pm 
Offline
Energizer Bunny
User avatar

Joined: Wed May 22, 2002 12:24 am
Posts: 1634
Pi wrote:
Vorn the Unspeakable wrote:
Things that compiler do that make you go "hmm..."

h:\Geodesate\main.cpp(40) : warning C4267: 'argument' : conversion from 'size_t' to 'unsigned int', possible loss of data

Don't jump so soon to call that stupid.


That's not the stupid part.
Quote:
Vorn the Unspeakable wrote:
out_file << " " << geodesation.sideToSize(size * 3 + 1);

Why does VS.NET not have a standard operator<<(ostream&, size_t)?

Complain to the folks who wrote the STL.


That is.

Vorn


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 14, 2004 1:45 pm 
Didn't MS write the windows implementation of STL? I know they're still working on string.

This one's better. In MSVS7 on warning level 4:
Code:
09 COORD c = {0, 0}; // COORD == struct { SHORT X, Y; };
10 short num = 1;
11
12 c.X += static_cast<SHORT>(num);

Code:
Thingy.cpp(12): warning C4244: '+=' : conversion from 'int' to 'SHORT', possible loss of data


Also, it won't pragma out warnings 4100 (unreferenced params) or 4706 (assignment in a conditional) unless you pragma out both.


Top
  
 
PostPosted: Thu Jul 15, 2004 10:58 am 
Offline
Nightstar Graveyard Daemon
User avatar

Joined: Mon Jun 03, 2002 8:30 pm
Posts: 1071
Location: Wouldn't you rather observe my Velocity?
Pi wrote:
Vorn the Unspeakable wrote:
Why does VS.NET not have a standard operator<<(ostream&, size_t)?

Complain to the folks who wrote the STL.


I'm with Vorn on this one. When standard type gets declared, corresponding istream and ostream operators should be declared as well, methinks.

This, of course, would result in needless compiler cycles for the majority of people who don't understand and correctly use the iostream classes, which is another argument either for the immiscibility of procedural and OO thinking, or for C++ having implemented a horrible OO model, and/or that strong typing should be considered harmful. :-)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group