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

  • Home
  • SEARCH
  • 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 6126583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:23:37+00:00 2026-05-23T16:23:37+00:00

Is it possible to recast the a variable permanently, or have a wrapper function

  • 0

Is it possible to recast the a variable permanently, or have a wrapper function such that the variable would behave like another type?

I would want to achieve something I posted in the other question:
Typecasting variable with another typedef

Update: Added GCC as compiler. May have a extension that would help?

  • 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-23T16:23:37+00:00Added an answer on May 23, 2026 at 4:23 pm

    Yes, you can cast a variable from one type to another:

     int x = 5;
     double y = (double) x; // <== this is what a cast looks like
    

    However, you cannot modify the type of the identifier ‘x’ in-place, if that is what you are asking. Close to that, though, you can introduce another scope with that identifier redeclared with some new type:

      int x = 5;
      double y = (double) x;
      {
          double x = y; // NOTE: this isn't the same as the 'x' identifier above
          // ...
      }
      // NOTE: the symbol 'x' reverts to its previous meaning here.
    

    Another thing you could do, though it is really a horrible, horrible idea is:

      int x = 5;
      double new_version_of_x = (double) x;  // Let's make 'x' mean this
      #define x new_version_of_x
      // The line above is pure evil, don't actually do it, but yes,
      // all lines after this one will think 'x' has type double instead
      // of int, because the text 'x' has been rewritten to refer to
      // 'new_version_of_x'. This will likely lead to all sorts of havoc
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Why do I see a double variable initialized to some value like
Possible Duplicate: Why does ReSharper want to use 'var' for everything? I have ReSharper
Possible Duplicate: C++ templates that accept only certain types For example, if we want
Possible Duplicate: How does the Google Did you mean? Algorithm work? Suppose you have
Possible Duplicate: JavaScript: var functionName = function() {} vs function functionName() {} What's the
Possible Duplicate: How to detect if JavaScript is disabled? I have a website which
Possible Duplicate: How to copy part of an array to another array in C#
Possible Duplicate: Why is my return type meaningless? Hi, I'm confused about a particular
Possible Duplicates: [.NET] How do I disable a system device? Win32 API function to
Possible Duplicate: Is there some ninja trick to make a variable constant after its

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.