Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Update expr.c #91

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
JebediahS wants to merge 1 commit into ohkimur:main
base: main
Choose a base branch
Loading
from JebediahS:patch-1
Open

Update expr.c #91

JebediahS wants to merge 1 commit into ohkimur:main from JebediahS:patch-1

Conversation

@JebediahS
Copy link

@JebediahS JebediahS commented Sep 5, 2025

Filling the stack should start from element with index 0.

Filling the stack should start from element with index 0.
Copy link
Owner

@ohkimur ohkimur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! The change from pre-increment/decrement to post-increment/decrement looks correct and fixes the off‐by‐one behavior:

  • In push, stack[stack_pointer++] = element; is the right choice if stack_pointer tracks the next free slot.
  • In pop, return stack[--stack_pointer]; correctly moves back to the last pushed element before reading.

A couple of suggestions to strengthen this and future contributions:

  • Add brief comments documenting the stack invariant: "stack_pointer points to the next free slot."
  • Include small tests (or a demo main) for: push/pop single item, push until full, pop until empty, and verify strict LIFO.
  • Consider returning a status from push/pop (e.g., int/bool with out‐param) instead of printing errors; returning 0 from pop is ambiguous if 0.0 is a valid value.
  • Use size_t for stack_pointer and comparisons with STACK_SIZE.
  • Optionally guard against overflow/underflow with asserts in debug builds.

Overall, nice, focused fix with clear correctness improvement. If you’re up for it, similar sanity checks and invariants across other stack/queue exercises would be super valuable.

Copy link
Author

Thanks for the PR! The change from pre-increment/decrement to post-increment/decrement looks correct and fixes the off‐by‐one behavior:

* In `push`, `stack[stack_pointer++] = element;` is the right choice if `stack_pointer` tracks the next free slot.
* In `pop`, `return stack[--stack_pointer];` correctly moves back to the last pushed element before reading.

A couple of suggestions to strengthen this and future contributions:

* Add brief comments documenting the stack invariant: "`stack_pointer` points to the next free slot."
* Include small tests (or a demo `main`) for: push/pop single item, push until full, pop until empty, and verify strict LIFO.
* Consider returning a status from `push`/`pop` (e.g., int/bool with out‐param) instead of printing errors; returning `0` from `pop` is ambiguous if `0.0` is a valid value.
* Use `size_t` for `stack_pointer` and comparisons with `STACK_SIZE`.
* Optionally guard against overflow/underflow with asserts in debug builds.

Overall, nice, focused fix with clear correctness improvement. If you’re up for it, similar sanity checks and invariants across other stack/queue exercises would be super valuable.

Thank you for the suggestions, I would be happy to contribute more (if my time allows)!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@ohkimur ohkimur ohkimur requested changes

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /