<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/a-reinterpret-cast-trap-noyt1yvas" -->

---
title: A reinterpret_cast Trap | daily.dev
description: A deep dive into a subtle C++ bug caused by misusing reinterpret_cast when converting derived class pointers to integral addresses. The post demonstrates how...
canonical: https://daily.dev/posts/a-reinterpret-cast-trap-noyt1yvas
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: A reinterpret_cast Trap | daily.dev
og:description: A deep dive into a subtle C++ bug caused by misusing reinterpret_cast when converting derived class pointers to integral addresses. The post demonstrates how...
og:url: https://daily.dev/posts/a-reinterpret-cast-trap-noyt1yvas
og:image: https://api.daily.dev/og/posts/nOYT1yVAS.png
og:image:alt: A reinterpret_cast Trap
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# A reinterpret_cast Trap

**[Jacek Galowicz](https://daily.dev/sources/galowicz)** · 6 min read · 0 upvotes · 0 comments

## Summary

A deep dive into a subtle C++ bug caused by misusing reinterpret_cast when converting derived class pointers to integral addresses. The post demonstrates how multiple inheritance and virtual functions can shift the memory layout of objects, causing reinterpret_cast to read the wrong member. The fix is to first use static_cast to the target base type before applying reinterpret_cast, allowing the compiler to correctly adjust the pointer offset. The post concludes with guidance on when to use each cast type and why C++ casts are intentionally verbose.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://galowicz.de/blog/reinterpret_cast_trap/>

## Similar posts on daily.dev

- [What reinterpret\_cast doesn't do](https://daily.dev/posts/what-reinterpret-cast-doesn-t-do-g4ungn0ba) · Andreas Fertig · 0 upvotes · 0 comments
- [Wages of Inheritance](https://daily.dev/posts/wages-of-inheritance-m0y7kf0tf) · The Daily WTF · 0 upvotes · 1 comments
- [The C\+\+ fundamentals your seniors think they know](https://daily.dev/posts/the-c-fundamentals-your-seniors-think-they-know-lgmt2lsp3) · C\+\+ · 0 upvotes · 1 comments
- [A Type of Type Safety](https://daily.dev/posts/a-type-of-type-safety-zraqmlpky) · The Daily WTF · 0 upvotes · 0 comments
- [C\+\+ float-to-int conversion can be undefined behavior](https://daily.dev/posts/c-float-to-int-conversion-can-be-undefined-behavior-omx9yobrw) · Lobsters · 0 upvotes · 0 comments

---

Tags: [#c++](https://daily.dev/tags/c++)

[View this post on daily.dev](https://daily.dev/posts/a-reinterpret-cast-trap-noyt1yvas)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"A reinterpret_cast Trap","url":"https://daily.dev/posts/a-reinterpret-cast-trap-noyt1yvas","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/a-reinterpret-cast-trap-noyt1yvas"},"datePublished":"2026-04-18T22:20:02.951Z","dateModified":"2026-04-18T22:50:43.813Z","description":"A deep dive into a subtle C++ bug caused by misusing reinterpret_cast when converting derived class pointers to integral addresses. The post demonstrates how...","image":"https://media.daily.dev/image/upload/s--HRgLpUt6--/f_auto/v1722860399/public/Placeholder%2003","thumbnailUrl":"https://media.daily.dev/image/upload/s--HRgLpUt6--/f_auto/v1722860399/public/Placeholder%2003","isAccessibleForFree":true,"articleSection":"Jacek Galowicz","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Jacek Galowicz","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/da946494d89c429fbc005c1a0a1b05ba","url":"https://daily.dev/sources/galowicz"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/a-reinterpret-cast-trap-noyt1yvas","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"c++","timeRequired":"PT6M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Jacek Galowicz","item":"https://daily.dev/sources/galowicz"},{"@type":"ListItem","position":3,"name":"A reinterpret_cast Trap"}]}
```

