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

  • Home
  • SEARCH
  • 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 170525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T12:49:25+00:00 2026-05-11T12:49:25+00:00

I was writing a function to figure out if a given system of linear

  • 0

I was writing a function to figure out if a given system of linear inequalities has a solution, when all of a sudden it started giving the wrong answers after a seemingly innocuous change.

I undid some changes, re-did them, and then proceeded to fiddle for the next two hours, until I had reduced it to absurdity.

The following, inserted anywhere into the function body, but nowhere else in the program, fixes it:

if(0) {     __asm__('nop\n');     __asm__('nop\n');     __asm__('nop\n');     __asm__('nop\n'); } 

It’s for a school assignment, so I probably shouldn’t post the function on the web, but this is so ridiculous that I don’t think any context is going to help you. And all the function does is a bunch of math and looping. It doesn’t even touch memory that isn’t allocated on the stack.

Please help me make sense of the world! I’m loathe to chalk it up to the GCC, since the first rule of debugging is not to blame the compiler. But heck, I’m about to. I’m running Mac OS 10.5 on a G5 tower, and the compiler in question identifies itself as ‘powerpc-apple-darwin9-gcc-4.0.1’ but I’m thinking it could be an impostor…

UPDATE: Curiouser and curiouser… I diffed the .s files with nops and without. Not only are there too many differences to check, but with no nops the .s file is 196,620 bytes, and with it’s 156,719 bytes. (!)

UPDATE 2: Wow, should have posted the code! I came back to the code today, with fresh eyes, and immediately saw the error. See my sheepish self-answer below.

  • 1 1 Answer
  • 1 View
  • 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. 2026-05-11T12:49:26+00:00Added an answer on May 11, 2026 at 12:49 pm

    I came back to this after a few days busy with other things, and figured it out right away. Sorry I didn’t post the code sooner, but it was hard coming up with minimal example that displayed the problem.

    The root problem was that I left out the return statements in the recursive function. I had:

    bool function() {     /* lots of code */     function() } 

    When it should have been:

    bool function() {     /* lots of code */     return function() } 

    This worked because, through the magic of optimization, the right value happened to be in the right register at the right time, and made it to the right place.

    The bug was originally introduced when I broke the first call into its own special-cased function. And, at that point, the extra nops were the difference between this first case being inlined directly into the general recursive function.

    Then, for reasons that I don’t fully understand, inlining this first case led to the right value not being in the right place at the right time, and the function returning junk.

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

Sidebar

Related Questions

I'm writing a function that fishes out the src from the first image tag
I'm writing an applet and want to figure out how to make a button
I am trying to figure out how to lock an entire table from writing
Whats this syntax useful for : function(String... args) Is this same as writing function(String[]
I'm writing a function for an installer DLL to verify the Authenticode signature of
Let's say that I'm writing a function to convert between temperature scales. I want
Say for instance I was writing a function that was designed to accept multiple
I am having some difficulty writing a function that will search through a directory
I find that I frequently end up writing a function that I always call
I'm writing an interactive function that I'd like to have remember the last argument

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.