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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:01:05+00:00 2026-06-17T17:01:05+00:00

While trying to debug a problem I’m having using Speex, I noticed that it

  • 0

While trying to debug a problem I’m having using Speex, I noticed that it (well, not just Speex, but some example code as well) does the following:

  • Return a pointer to EncState from an initialization function
  • Cast that pointer to a void pointer
  • Store the void pointer
  • (elsewhere)
  • Cast the void pointer to a pointer to pointer to SpeexMode
  • Dereference the pointer

It so happens that the definition of EncState starts with a field of type SpeexMode *, and so the integer values of a pointer to the first field and a pointer to the struct happen to be the same. The dereference happens to work at runtime.

But… does the language actually allow this? Is the compiler free to do whatever it wants if it compiles this? Is casting a struct T* to a struct C* undefined behavior, if T''s first field is a C`?

  • 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-06-17T17:01:06+00:00Added an answer on June 17, 2026 at 5:01 pm

    From the C11 standard:

    (C11 §6.7.2.1.15: “A pointer to a structure object, suitably
    converted, points to its initial member … and vice versa. There may
    be unnamed padding within as structure object, but not at its
    beginning.”)

    Which means that the behavior you see is allowed and guaranteed.

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

Sidebar

Related Questions

While trying to troubleshoot a problem I'm having with a project, I noticed that
I'm trying to debug a problem with some legacy code. While trying to understand
Today I experienced a weird problem while trying to remotely debug an application built
Very simple problem...but weird results. Im just trying to fill a drop down list
I'm having a problem while trying to switch between a group of photos in
I just spent hours trying to debug my code. The whole problem boiled down
I'm just getting started using ADO.NET and DataSets and DataTables. One problem I'm having
*edit: this particular situation was created while I was trying to debug another problem,
I'm having problem from a while (since I'm using visual studio 2010 I think).
While trying to debug a different problem, I created an HTML file with the

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.