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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:03:29+00:00 2026-06-05T12:03:29+00:00

1 #include string 2 using namespace std; 3 4 bool m_bInited = true; 5

  • 0
 1 #include "string"
 2 using namespace std;
 3 
 4 bool m_bInited = true;
 5 int  m_imaxsize = 100;
 6 
 7 int test()
 8 {
 9     if (!m_bInited)
10     {
11         return -1;
12     }
13 
14     std::string gbkInput = "";
15     std::string utf8Input = "";
16     if (gbkInput.size() > m_imaxsize)
17     {
18         return 1;
19     }
20     return 0;
21 }
22 
23 int main()
24 {
25     test();
26     return 0;
27 }

when using gdb step from line 16, the debug sequence is:

line 16 -> line 20 -> line 18 -> line 21.

    (gdb) b 16
    (gdb) r
    Breakpoint 1, test () at main.cpp:16
    16          if (gbkInput.size() > m_imaxsize)
    (gdb) n
    20          return 0;
    (gdb) n
    18              return 1;
    (gdb) n
    21      }

compile: g++ -g main.cpp -o test

why gdb display line 18 ? and the test() return value is 0.

my gcc version is 4.1.2.
GNU gdb Fedora (6.8-37.el5) or GNU gdb (GDB) Red Hat Enterprise Linux (7.0.1-37.el5) .
Both gdb version has this problem.

BTW: if move line 14,line 15 (these 2 string var) to line 9, it will be ok. gdb will not display line 18 !
it seemed the string var cause this bug.

Can everyone help me?
Thank you!

  • 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-05T12:03:30+00:00Added an answer on June 5, 2026 at 12:03 pm

    This behavior is a “feature” of older versions of gcc/gdb, and it’s been reported here before: gdb unexpected behavior: in nested if. Note: This question can’t be marked as a duplicate of that other as there was no satisfactory solution.

    The statement isn’t being executed. It just looks like it.

    Addendum
    It’s easy to verify that the statement is not being executed. Add a function

    int one() {
       return 1;
    }
    

    Then replace that return 1; with return one(); gdb will print return one(); but it does not call the function one(). Apparently there’s a problem in older versions of gdb with displaying the execution of the close brace on an if statement.

    Note well: This only happens with older versions of gdb, and it’s apparently a problem of display rather than of incorrect program execution.

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

Sidebar

Related Questions

#include <iostream> #include <string.h> using namespace std; int main() { int e=0; int b=0;
#include <iostream> #include <string> using namespace std; string crash() { } int noCrash() {
#include <iostream> #include <string> #include <fstream> using namespace std ; string strWord( int index
#include<iostream> #include<stdlib.h> #include<string.h> #include<stdio.h> using namespace std; union type{ int a; char b; int
#include <iostream> #include <string> #include <vector> #include <algorithm> using namespace std; int main(void) {
Here's my code so far: #include<iostream> #include<string> #include<fstream> using namespace std; int main() {
Having a program like this: #include <iostream> #include <string> using namespace std; class test
#include <iostream> #include <cmath> #include <string> using namespace std; string STRING; bool isEqual(double a,
#include <iostream> #include <string> using namespace std; void bubbleSort(int data[], int n); int main()
#include <iostream> #include <string> using namespace std; class A { public: A() { i=1;

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.