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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:55:35+00:00 2026-05-24T05:55:35+00:00

Should one avoid using recursive call of functions in C/C++? I work on machine

  • 0

Should one avoid using recursive call of functions in C/C++?

I work on machine learning/data mining, so it is very critical for me to make my code scalable.

When I was using Java, I avoided using recursive call as much as possible because I often got my call stack overflowed. Although there are options to control the amount of memory assigned to the call stack, I thought having my program dependent on smaller number of parameters is more desirable. Therefore when it is clear how to implement without recursive call, possibly using a stack managed by myself, I did so. But I am not sure this is a right discipline even in Java.

In my knowledge, there is no call stack in C/C++, so I would not worry about overflowing it. Thus, I am curious: would one try to avoid using recursion, or is it encouraged, or it is problem specific, in terms of scalability of your program?

  • 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-24T05:55:36+00:00Added an answer on May 24, 2026 at 5:55 am

    The call stack in C & C++ is kind of like the vtable in C++ in one respect – it’s not mentioned in the standard as far as I know, i.e., that implementation is not mandated, but for all practical purposes, it’s almost always implemented that way.

    Granted there are some esoteric architectures, especially in the embedded world, that might eschew the stack. The PIC is an example of a stack-unfriendly architecture, and some tiny microcontrollers don’t support a stack, and least not directly. And in certain situations use of the stack can be eliminated anyway (inline functions or aggressive optimization for function calls, use of registers for local variables instead of stack space).

    Anyway, to your question… this is a very subjective question that usually boils down to one question: can you afford it?

    If you have enough stack space and the recursion won’t be deep enough to blow your stack, recursion is often the right choice. Not always, but often.

    But you have to understand your architecture, your platform, your toolset, etc. and know how large your stack is. With many multi-tasking embedded systems, for example, your stack size is determined at the time the thread/task is created, and it won’t “grow as needed”. Other simple (embedded) systems only use a single stack, or maybe one “background” stack and one interrupt stack. Still others allow the stack to grow as needed, within limits, depending on the processor & operating system.

    If you’re coming from a Java background, I’m not surprised if this kind of discussion is new to you.

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

Sidebar

Related Questions

I recall that one should always avoid using recursive method calls in Java .
I read in the docs that one should avoid using finish() - but I
Starting a new big C multiplatform project, what rules should one follow to avoid
How much should one DataSet represent? Using the example of an ordering system: While
There are numerous posts out there stating one should avoid the use of UITableViewController.
There are numerous posts out there stating one should avoid the use of UITableViewController.
It is recommended that type names and virable names should avoid using abbreviations. It
Should one create unit tests involving IO? Ie, testing a class method for serializing/deserializing
Where should one go to be kept updated on all of the security flaws/problems
When should one use a scripting language over a more verbose, compiled language like

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.