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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:51:54+00:00 2026-05-14T04:51:54+00:00

I’ve been reading StackOverflow too much and started doubting all the code I’ve ever

  • 0

I’ve been reading StackOverflow too much and started doubting all the code I’ve ever written, I keep thinking “Is that undefined behavour?” even in code that has been working for ages.

So my question – Is it safe and well defined behavour to cast a pointer to an object (In this case abstract interface classes) to a void* and then later on cast them back to the original class and call method using them?

I’m fully aware that the code that does this is probably awful. I wouldn’t even consider writing it like this now (this is old code which I don’t really want to change), so I’m not looking for a discussion of better ways to do this. I already know how to write it better if I ever did this again. But if it’s actually broken to rely on this in C++ then I’ll have to look at changing the code, if it’s merely awful code then changing it won’t be a priority.

I would have had no doubts about something this simple a year or two ago but as my understanding of C++ increases I actually find I have more and more worries about code being safe under the standards even if it works perfectly well. Perhaps reading too much stack overflow is a bad thing for productivity sometimes 😛

  • 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-14T04:51:54+00:00Added an answer on May 14, 2026 at 4:51 am

    You are safe.

    From C++(0x) draft,

    §5.2.9/13 (for static_cast):

    A value of type pointer to object converted to “pointer to cv void” and back, possibly with different cv-qualification, shall have its original value.

    §5.2.10/7 (for reinterpret_cast):

    Converting an rvalue of type “pointer to T1” to the type “pointer to T2” (where T1 and T2 are object types and where the alignment requirements of T2 are no stricter than those of T1) and back to its original type yields the original pointer value.

    (Of course, casting to an unrelated class is undefined behavior.)

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

Sidebar

Ask A Question

Stats

  • Questions 418k
  • Answers 418k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Ignore me. I'm sorry everyone. I'd mistyped the url of… May 15, 2026 at 9:54 am
  • Editorial Team
    Editorial Team added an answer Worked code: function queen clc; counter = 0; n =… May 15, 2026 at 9:54 am
  • Editorial Team
    Editorial Team added an answer http://mobiready.com/launch.jsp?locale=en_EN Emulators http://www.winwap.com/downloads.php http://developer.openwave.com/dvl/tools_and_sdk/phone_simulator/choosing.htm http://www.forum.nokia.com/info/sw.nokia.com/id/d57da811-c7cf-48c8-995f-feb3bea36d11/Nokia_Mobile_Internet_Toolkit_4.1.html http://msdn.microsoft.com/windowsmobile/downloads/tools/install/default.aspx http://emulator.mtld.mobi/emulator.php http://www.wapsilon.com/ May 15, 2026 at 9:54 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.