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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:38:18+00:00 2026-05-14T21:38:18+00:00

I want to do it: int main () { bla bla bla void *onetype;

  • 0

I want to do it:

int main () {
  bla bla bla

  void *onetype;

  switch (USER_INPUT_TYPE) {

      CASE CONVERT_TO_CHAR:
          convert onetype VOID TO CHAR >>> HOW???

      CASE CONVERT_TO_INT:
          convert onetype VOID TO INT >>> HOW???

   LOT OF CASES...
   }
}

Yes, I know type casting, but type casting is a ‘temporary’ change.

So, is there any way to accomplish it in C?

EDIT :

Stop stop stop! Please, see, what are you doing is type casting, I KNOW THIS, you are creating another variable of the desirable type like int i = (int) onetype, I don’t want this, I want something else like onetype = (int) onetype, without recreate them, without allocate another variable.

Thanks a lot guys!

  • 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-14T21:38:19+00:00Added an answer on May 14, 2026 at 9:38 pm

    What you want is run-time type information – to have a variable in which the type is only determinable at run time. C does NOT have this functionality in the language – once the program is compiled, types are erased, and only memory blobs exist. Dynamic languages maintain type information and implement this natively.

    You can devise your own home-grown type tagging system:

    typedef union {
    int i;
    char c;
    float f;
    } evil;
    
    typedef struct {
      evil value;
      int type;
    } tagged_t;
    
    enum {
      TYPE_INT, TYPE_CHAR, TYPE_FLOAT
    };
    
    tagged_t bar;
    bar.value.c = 'a';
    bar.type = TYPE_CHAR;
    

    Now every time you wish to use your tagged_t type, you must implement a condition for each possible type of variable you are storing, or be able to determine whether a type is allowed in that area of code or not.

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

Sidebar

Related Questions

No related questions found

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.