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 3350002
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:44:02+00:00 2026-05-18T01:44:02+00:00

I have the following minimal code: using namespace System; long get_prop( Object^ v )

  • 0

I have the following minimal code:

using namespace System;

long get_prop( Object^ v )
{
    return Convert::ToInt32( v );
}

int main()
{
    Object^ o1 = gcnew Int32( -1 );
    Object^ o2 = gcnew UInt32( 0xFFFFFFFF );
    long value1 = get_prop( o1 );
    long value2 = get_prop( o2 );

    return 0;
}

It gives the OverflowException exception in get_prop function. In the end I need to use the result of get_prop in pure C++ code. What is the correct way to write get_prop function so it can work without exception in both cases. Can I use some sort of templates as in C++ or there more trivial solution?

  • 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-18T01:44:03+00:00Added an answer on May 18, 2026 at 1:44 am

    Hmya, you are trying to stuff a 32-bit pig in a 31-bit poke. This code ends up calling Convert::ToInt32(UInt32 value) which looks like this:

    public static int ToInt32(uint value)
    {
        if (value > 0x7fffffff)
        {
            throw new OverflowException(Environment.GetResourceString("Overflow_Int32"));
        }
        return (int) value;
    }
    

    Kaboom. Not sure what kind of overflow behavior you want, but this lets the compiler do the ignoring and avoids the exception:

    long get_prop( Object^ v )
    {
        return (long)Convert::ToInt64( v );
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider I have the following struct : struct IDirect3D { IDirect3D() : ref_count_(0) {}
See the following class public class Parent { private String name; private int age;
Please, consider the following (I'm sorry for the amount of code; but this is
I have a tree of objects, where each object has a std::vector of pointers
Have following setup: MainActivity class - extends activity MyLayout class - extends View Prefs
I have following string: <div> text0 </div> prefix <div> text1 <strong>text2</strong> text3 </div> text4
i'm writing a C# class to perform 2D separable convolution using integers to obtain
we're currently developing an application that makes extensive use of popup windows(*) and have
I am looking for some native JavaScript, or jQuery plugin, that meets the following
In the 2nd edition of The C Programming Language by Kernighan and Ritchie they

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.