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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:52:12+00:00 2026-05-23T23:52:12+00:00

I was reading this thread: Typecasting variable with another typedef type_b *sample_b = (type_b

  • 0

I was reading this thread: Typecasting variable with another typedef

type_b *sample_b = (type_b *) ((void *) &sample);

Isn’t (void *) extraneous? &sample would return a pointer of type: type_a, which can be cast directly to (type_b *). Why the extra (void *)? I feel it’s wrong, but am not confident enough in my C – hence the extra verification.

  • 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-23T23:52:12+00:00Added an answer on May 23, 2026 at 11:52 pm

    Casting the pointer to type void hides the pointer’s true type from the compiler so you can cast it to whatever different type you want and the compiler will not have enough information to know if it’s valid or not, thus it will allow it.

    Without doing this, the compiler will – at a minumum – complain that you are trying to cast a pointer from one type to another incompatible type.

    IMPORTANT NOTE:

    The original poster of the question you referenced is trying to do something dangerous. The assumption is the alignment of the structures in memory will be the same, allowing them to access the two individual char’s as if they were a single array of two chars. This may be true in theory and will probably work in a small test program, but if this is done in a piece of production code, it will absolutely end in tears and gnashing of teeth at 3am.

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

Sidebar

Related Questions

I was reading this thread/post: https://stackoverflow.com/questions/262298/windows-c-ui-technology and am also wondering about a non .NET
I was just reading this thread and it occurred to me that there is
After reading many of the replies to this thread , I see that many
After reading this thread: How to force browser to reload cached CSS/JS files? I
After reading this thread: NSUserDefaults not present on first run on simulator I know
I was recently reading this thread , on some of the worst PHP practices.
I was just reading this thread and wondered if it's easier to become a
After reading this thread What does the explicit keyword mean in C++? I made
I'm reading some data from a DB in an AsyncTask thread.... in this way:
I have two threads, one updating an int and one reading it. This is

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.