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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:19:49+00:00 2026-05-30T05:19:49+00:00

I have a struct that is declared on the stack. Here is what the

  • 0

I have a struct that is declared on the stack. Here is what the struct looks like:

struct MyStruct {
    int integer;
    std::vector<bool > booleanVector;
};

When I step through the following function with gdb, printing the value of s.integer and s.booleanVector.size(), the statements seem to have no effect.

MyStruct getMyStruct()
{
    MyStruct s;   
    s.integer = 3;
    s.booleanVector.resize( s.integer );
    return s;
}

However, when I insert print statements such as std::cout << s.integer << std::endl; the output shows that the values of s.integer and s.booleanVector.size() have been properly changed.

I discovered that the problem seems to be associated with the struct being returned by the function in which it is declared. The problem with gdb displaying invalid information about the struct does not occur if it is not being returned by the function in which it is declared.

This is a simplified example that exhibits a problem I had while attempting to debug a project. This problem with gdb was distracting me from an actual error in my code and making it difficult to find (originally I thought the problem might be a subtle bug in my code, which is why I posted it here). Here is a complete small program that exhibits this behaviour on my system.

I guess my question is if this is just a bug with gdb or does this behaviour occur as a result of how gcc handles structs / classes that are to be returned from a function.

Note: Using gdb 6.3 with gcc 4.2 in Mac OSX 10.6 (Snow Leopard)

  • 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-30T05:19:51+00:00Added an answer on May 30, 2026 at 5:19 am

    This debugging issue is fixed by upgrading to a more recent version of gcc. When the code is compiled with gcc 4.7, gdb displays correct information about the struct.

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

Sidebar

Related Questions

I have a code that looks something like: struct Data { int value; };
I have a struct that looks something like this: [StructLayout(LayoutKind.Sequential)] public struct in_addr {
I have an unmanaged struct I'd like to marshal to c sharp that looks
I have declared a structure that look like typedef struct { char* key; char*
I have a struct that I initialize like this: typedef struct { word w;
I have class foo that contains a std::auto_ptr member that I would like to
Say I have a simple struct that contains a vector and defines a copy
I have some code that returns a struct containing 2 objects (declared as id
Say I have a struct declared like the following: public struct Test { public
I have structs, let's call them sn, that look like: struct sn { string

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.