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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:19:55+00:00 2026-05-26T18:19:55+00:00

I am about to debug something within my boost asio socket communication. And found

  • 0

I am about to debug something within my boost asio socket communication. And found this piece of code inside of the asio library (found in boost/asio/impl/write.hpp line 169 (boost 1.47) ):

  switch (start)
  {
    case 1:
    buffers_.prepare(this->check_for_completion(ec, total_transferred_));
    for (;;)
    {
      stream_.async_write_some(buffers_,
          BOOST_ASIO_MOVE_CAST(write_op)(*this));
      return; 
    default:
      total_transferred_ += bytes_transferred;
      buffers_.consume(bytes_transferred);
      buffers_.prepare(this->check_for_completion(ec, total_transferred_));
      if ((!ec && bytes_transferred == 0)
          || buffers_.begin() == buffers_.end())
        break;
    }

    handler_(ec, static_cast<const std::size_t&>(total_transferred_));
  }

I have already a lot of years of C/C++ development experience, but never ever in my life I saw such kind of weird implementation. Look there, the default: label of the switch statement is within the for loop.

If I understand this right, then the switch statement is “misused” instead of a goto, right (for the cases where start != 1, goto default:)?
Is it actually a valid C/C++ with respect to the standard?
What will happen if I for example put

for(int i=0; i < 10; i++)

instead of the for loop in the original code. Will “i” be undefined in case when jump is performed to default: label? Sure I might use a debugger here, however this seems so suspicious for me, that I think this could produce different behavior for different compilers.

  • 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-26T18:19:56+00:00Added an answer on May 26, 2026 at 6:19 pm

    This is well-defined, valid code. A switch really is a glorified goto. For some clever use of this construct, take a look at Duff’s device.

    As for your for, that wouldn’t be legal. A jump to a case label can’t cross an initialization.

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

Sidebar

Related Questions

I know about this question: Which (third-party) debug visualizers for Visual Studio 2005/2008 do
I would like to do something like this : def main(): Display Information about
I asked this question about how to debug server side applications and I think
Similar to this problem here: Old Question about C# debugging I'm trying to debug
Is there something wrong with the .dll file? Shouldn't it just consider the code
Using intellij and maven pom files, how do i debug tests run inside the
How would I quickly debug helper methods in script\console. I'm talking about making changes
I came about a rather weird problem today. I have a math library optimized
i have started learning something about log4j as so far its working fine here
I have this post that teaches me about pdb file and StackTrace. This is

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.