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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:19:23+00:00 2026-05-28T03:19:23+00:00

Because anything from C++ and beyond have nice constructs that handles a stack like

  • 0

Because anything from C++ and beyond have nice constructs that handles a “stack” like behavior(vectors, lists, array lists, etc), I want to keep the question in terms of C.

So, I am learning about compilers, stacks, inscript and postscript, parsers, lexers, and everything else that involves putting a compiler together as I will be required to later on in the my course for this semester. I want to make sure that my understanding of stacks is solid.

I believe I have the general idea on how one is put together. Basically you have an array following LIFO model. When you add an element, it is “pushed” in on the end of the array and “popped” off when removed. No issue there. My concern comes whith some the implementation detail. How are things like number of elements tracked? How large should a stack be initialized to? Should I use a structure to hold those details together? Are variables global?

My professor has already handed us some source code in relation to our assignment, I am just looking for some supplemental details for my own understanding (generally I have to put something together myself before getting an understanding of someone else’s code). In most of my programming experience, the stack was some magical place that was beyond my control, but would explode if my recursive functions got too deep (SO anyone?).

Thanks in advance.

EDIT:

Ok, one thing I think I need to clarify is that I am not making a “true” stack, but will be required to take a an infix epxression and convert it to postfix. I am looking at the stack data structure so anything architecure related may not apply in this since. I was given the impression a stack was the way to handle this, likewise with rule reduction described in BNF notation.

  • 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-28T03:19:23+00:00Added an answer on May 28, 2026 at 3:19 am

    What kind of stack are you talking about, here?

    Most CPU architectures have a notion of a stack, which is how the CPU tracks function calls, basically. C is typically compiled to use the same stack for this purpose, and also often to use it for argument-passing.

    Such “architectural” stacks don’t require much, typically there’s a register in the CPU that points to the top of the stack. It’s the job of the operating system to make sure that every time a process starts, that process has a valid stack pointer. This is done by allocating the memory and initializing the register to the proper address. Modern “large” OS:es with virtual memory and so on often support growing the stack dynamically on demand.

    The number of elements in the stack is not explicitly tracked in such cases, you can compute the number of bytes used by inspecting the current stack pointer and comparing to the process’ (assumed known) “stack start”, but that doesn’t tell you about the internal structure of those bytes. This is normal for such low-level constructs.


    If, as nos hints in a comment, you’re really talking about a stack data structure, then there is no standard implementation for such a thing in C. It’s possible to imagine many possible API:s, for instance:

    typedef struct _Stack Stack;
    
    Stack * stack_new(size_t element_size, size_t initial_depth, int allow_growth);
    int     stack_push(Stack *stack, const void *element);
    int     stack_pop(Stack *stack, void *element);
    void    stack_peek(const Stack *stack, void *element);
    size_t  stack_depth(const Stack *stack);
    void    stack_clear(Stack *stack);
    

    The above API leaves the initial depth and whether or not the stack should grow once you try to go beyond the limit up to the user. This is sensible for a general-purpose API, in my opinion.

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

Sidebar

Related Questions

If we've learned anything from HTML/CSS it's that, declarative languages (like XML) do a
I would like to sync my db (tasks on my db, that have a
I have a UIView in a table view section header that I would like
I've never used ASIHTTPRequest before, nor have I dealt with posting anything from an
Because wikipedia is open source, I can modify anything I want. But what happens
Because Canvas3D doesn't have the ability to resize dynamically with the parent frame, I
Because I am a newbie I am trying to log out any errors that
I have three tables from a dataset ds. var test0 = from a in
It is generally considered bad practice to accept input that is derived from JavaScript
Quick question. I have a listbox being populated from a directory listing. Each file

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.