- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Warning 2259 can be useful for finding casts from 64-bit ints to 32-ints, but how can I make the message go away once I've confirmed the cast is legitimate? I know I could use pragmas to turn the warning off and back on, but that tends to make the code very hard to read. Is there some idiom I could put in a macro like this?
i32 = VALID_I64_TO_I32_CAST (i64);
Thanks.
i32 = VALID_I64_TO_I32_CAST (i64);
Thanks.
Link Copied
7 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Likewise error 1684. We make many, many legitimate conversions between pointers and ints. I can't seem to find a sequence of casts that will suppress the warning.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
A small example illustrating what you are talking about may help us to proceed with discussion. On the face of it, I don't know why a simple (int) cast shouldn't suppress warnings about assigning (long long) or equivalent to an int.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - tim18
A small example illustrating what you are talking about may help us to proceed with discussion. On the face of it, I don't know why a simple (int) cast shouldn't suppress warnings about assigning (long long) or equivalent to an int.
You're right -- it's not happening everywhere. It took a little doing to reproduce, but here's two otherwise identical functions, one that has a 2259 warning and the other that does not. Note that this is a plain C file and requires the "/Wp64" compiler option.
#include
void getInt_WARNING (int *pi)
{
*pi = (int) (time (0) / 60);
}
void getInt_quiet (int *pi)
{
time_t tt;
tt = time (0) / 60;
*pi = (int) tt;
}
This is a big deal for us because the code that generates the warnings is in macro expressions that cannot be re-written in this manner.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - Stuart Ferguson
You're right -- it's not happening everywhere. It took a little doing to reproduce, but here's two otherwise identical functions, one that has a 2259 warning and the other that does not. Note that this is a plain C file and requires the "/Wp64" compiler option.
#include
void getInt_WARNING (int *pi)
{
*pi = (int) (time (0) / 60);
}
void getInt_quiet (int *pi)
{
time_t tt;
tt = time (0) / 60;
*pi = (int) tt;
}
This is a big deal for us because the code that generates the warnings is in macro expressions that cannot be re-written in this manner.
If Wp64 did operate at a higher level, I would have reservations myself about portability of such casts on time_t objects. Noting that difftime() is the safe way to perform arithmetic on time_t objects, I'm a little surprised there aren't more ways to get warnings about this. I don't know how you could assure yourself of never supporting a platform where this would break, unless you run a testsuite to reject platforms where you would run into trouble.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - tim18
If Wp64 did operate at a higher level, I would have reservations myself about portability of such casts on time_t objects. Noting that difftime() is the safe way to perform arithmetic on time_t objects, I'm a little surprised there aren't more ways to get warnings about this. I don't know how you could assure yourself of never supporting a platform where this would break, unless you run a testsuite to reject platforms where you would run into trouble.
Well, sure, it may not be a safe cast to perform depending on context. What's odd is that the cast to int is allowed when performed on an int64 variable directly, but generates a warning when the cast is performed on an expression involving int64 values. That seems like a compiler issue.
In any case we'll remove /Wp64 if it is no longer supported.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - Stuart Ferguson
Well, sure, it may not be a safe cast to perform depending on context. What's odd is that the cast to int is allowed when performed on an int64 variable directly, but generates a warning when the cast is performed on an expression involving int64 values. That seems like a compiler issue.
In any case we'll remove /Wp64 if it is no longer supported.
Stuart, I've submitted a problem report to our front end team to take a look at this. I'm pushing for this warning to be quieted when an explicit cast to int exists.
Microsoft Visual C++* has deprecated /Wp64. We have not though, and our switch is different in behavior from Microsoft's in any event.
Note though that any change in behavior would only likely happen in a future major compiler version. In other words, don't expect this to be addressed in any 11.1 updates.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Stuart,
Why not insert the getInt_quiet format into the macro (add the time_t variable). The compiler optimizatons will (should) squish it out.
#define MINUTES(pi) { time_t tt = time (0) / 60; *pi = (int) tt; }
I am guessing at your macro.
Jim Dempsey

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page