Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 191081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:18:39+00:00 2026-05-11T16:18:39+00:00

Is there a flag for gcc such that conversions from a long to a

  • 0

Is there a flag for gcc such that conversions from a long to a short will generate a warning about a possible loss of data?

I’m working on a C++ application that is compiled for both Visual Studio (2005) and GCC 4.2 (for Mac OS X).

The warnings that Visual Studio prints out follow this pattern:

: warning C4244: 'argument' : conversion from 'long' to 'short', possible loss of data

I’ve tried -Wconversion, but that isn’t quite what I’m looking for. The only thing I’ve been able to find so far is an experimental flag, -Wcoercion, which is associated with GCC 4.3 (which I’m not sure if we want to invest in quite yet).

April 22, 2009 @ 11:00 EST Edit:To clarify, I want to see that warning. We have code where we want to know when a data loss would occur. If I have the code:

unsigned long value1 = LONG_MAX;
std::cout << "value1: " << value1 << std::endl;

unsigned short value2 = value1;
std::cout << "value2: " << value2 << std::endl;

I get this expected result:


  value1: 2147483647
  value2: 65535

In our code, we have special asserts put in place that perform the coercion and warn us if the executed-code would result in a loss of data. We found the places in our large code base using Visual Studio’s warnings.

Is there any way we can generate these warnings in gcc 4.2?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T16:18:39+00:00Added an answer on May 11, 2026 at 4:18 pm

    This feature is not supported in GCC 4.2, but it has been added in GCC 4.3. Wiki page explaining it.

    Thanks to schnaader and Evan Teran for providing the links that led me there.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to know if there is any gcc flag that doesn't compile
Is there a gcc flag to skip resolution of symbols by the compile-time linker
I want to allocate more memory to program.l What is the gcc flag that
In fact, -static gcc flag on Linux doesn't work now. Let me cite from
Is there any way to do the following in HQL: SELECT case when flag
I wonder is there any positive effect in using UNSIGNED flag on defining some
There is a conversion process that is needed when migrating Visual Studio 2005 web
I have a number of very long arrays. No run-time sort is possible. It
Is there a flag or other reliable method to detect if a compiled C++
To compile my C++ code I use the -W flag, which causes the warning:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.