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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T23:26:46+00:00 2026-05-21T23:26:46+00:00

Below is a snippet that gets programmatically generated for a toy programming language, actual

  • 0

Below is a snippet that gets programmatically generated for a toy programming language, actual code is different but following shows what it does when executed,



class Base{ };

Base b;

class Derived{
      int fibo(int i){
        if(i SMALLER 2)
          return 1;
        else
          return (Derived)b.fibo(i-1) + (Derived)b.fibo(i-2);
      }
};

//then somewhere in main

b = new Derived();
int i = (Derived)b.fibo(10);


My question is will GCC consider this for tail call elimination?

EDIT: Turns out my my view of TOC is a bit flawed, so in a different case a different function with a single return positioned at the tail, would that be considered for optimization? The reason I ask is that there bunch of scheme to c compilers and AFAIK scheme mandates TOC so there must be a way to force this?

  • 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-21T23:26:47+00:00Added an answer on May 21, 2026 at 11:26 pm

    How can it eliminate a tail call if there is no tail call? It’s only a tail call if it’s the very last thing done before a return – but you’re calling it twice, storing the results somewhere, add them and then you return. So: Generally, no.

    If the method is not virtual (i.e. GCC can be sure there’s only one implementation of fibo that’s called), it may still be able to optimize it (at least it worked for one user with a free function), but you’ll have to test it and propably shouldn’t rely on it. Turning recursion into tail recursion is generally the programmer’s job.

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

Sidebar

Related Questions

In the below code snippet can i replace char * to const char *
I am using the code snippet below, however it's not working quite as I
I have a table defined (see code snippet below). How can I add a
Below is the code snippet with comments which describes the problem statement. We have
For instance in the snippet below - how do I access the h1 element
Below is the code of a simple html with a table layout. In FF
According to the Rails API (snippet below), the optimal way to receive mail is
The snippet below loops through some web pages, grabs the html and then looks
I have replicated a stripped-down version of my code that has recently been re-written
Based on the below snippet from a silverlight control how do I make the

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.