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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T00:20:23+00:00 2026-05-20T00:20:23+00:00

I have a large application that I am working on in C++, and we

  • 0

I have a large application that I am working on in C++, and we have a class where the inline functions are returning the wrong value. It looks like they are offset by one entry.

Here is an example of how the code is set up:

class Test
{

private:
    uint myVal1;    
    uint myVal2;
    uint myVal3;
    uint myVal4;

public:
    uint myFunct1() const { return myVal1 };
    uint myFunct2() const { return myVal2 };
};

What we are seeing is that myFunct1 returns myVal2 and myFunct2 returns myVal3. If I dont make the functions inlined everything works as expected.

Any ideas on why this would be happening?

Thanks in advance.

  • 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-20T00:20:23+00:00Added an answer on May 20, 2026 at 12:20 am

    (I assume that what you posted above is actually a fragment from some header file.)

    Things like that typically happen when different source files in your program are compiled with different memory-layout-related settings, like class packing and alignment settings. Your header file is included into these different translation units and is interpreted differently because of the discrepancies in memory-layout settings.

    Once you start passing your Test objects between these translation units, the problem reveals itself. One translation unit creates a Test object with one memory layout, then another translation units reads it or writes into it assuming a totally different memory layout. In your case it is your inline functions that get interpreted differently in each translation unit.

    If you define your member functions as non-inline ones, they will assume the class memory layout specific to the source file in which they are defined. This will sweep the problem under the carpet and make things “work” (since the access functions are now tied to one memory layout), but nevertheless it is still not a good situation to have. It still can lead to various problems of similar nature down the road.

    Make sure all source files in your program are compiled with exactly the same class memory layout settings.

    P.S. As Fred noted in the comments, the discrepancy in the class memory layout between translation units can be caused by something as prosaic as forgetting to recompile a source file after modifying a header file the source file depends upon.

    Another “popular” source of such problems is class definitions that depend on preprocessor directives (i.e. class layout “customized” by #ifdef/#endif segments). If you forget to #define something important in some source file that includes your header file, you might end up with different memory layout for the class in that source file.

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

Sidebar

Related Questions

I have a NSIS script that is working well for a large application. I
I have a large application that uses EJB 2.x entity beans (BMP). This is
I have a rather large application that has literally a hundred DDLs with Yes
I have a fairly large application that uses WPF for its user interface. I
I have a semi-large web application that we run locally and I need to
I have a large Compact Frameworks V2.0 application that in most cases works very
I have a very large set of permissions in my application that I represent
I have an application that outputs large amounts of text data to an MFC
I have a web application that is becoming rather large. I want to separate
I have a Flex application that calls a function which searches a large document

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.