Skip to content

Update mpca_lang() example by add null terminated argument#182

Open
bruhtus wants to merge 1 commit intoorangeduck:masterfrom
bruhtus:chore/update-mpca-lang-usage
Open

Update mpca_lang() example by add null terminated argument#182
bruhtus wants to merge 1 commit intoorangeduck:masterfrom
bruhtus:chore/update-mpca-lang-usage

Conversation

@bruhtus
Copy link

@bruhtus bruhtus commented Oct 23, 2025

First of all, thank you for the book. This book help me a lot when i am trying to learn C, especially looking at the mpc parser source code (even though i still have no idea for the majority of the code 😅).

In the current version of mpc parser, we can add NULL at the end of arguments mpca_lang() to indicate that it's the end of argument when trying to find parser and prevent segfault error.

This changes update the snippet for the web version and example that use mpca_lang() by adding NULL at the end of mpca_lang() argument.

This changes also resolves issue #147.

In the current version of mpc parser, we can add NULL add the end of
arguments mpca_lang() to indicate that it's the end of argument when
trying to find parser and prevent segfault error.

This changes update the snippet for the web version and example that use
mpca_lang() by adding NULL at the end of mpca_lang() argument.
@bruhtus
Copy link
Author

bruhtus commented Oct 23, 2025

I've been thinking, should we add some explanation about NULL at the end of mpca_lang() arguments in chapter 5 (the earliest chapter that introduce mpca_lang())?

Something like "NULL at the end of mpca_lang argument is to indicate the end of the parser used, the one we initialized using mpc_new()". 🤔

@orangeduck
Copy link
Owner

Thanks a lot!

I think this was probably the original reason I didn't add it in the first place: it is difficult to explain the purpose of it without getting into the weeds: what is NULL? What are pointers? What are variable argument functions? Why don't they already know the number of arguments they are provided etc. etc.

@bruhtus
Copy link
Author

bruhtus commented Oct 24, 2025

Yeah, it's kind of difficult to explain, especially on the earlier chapter. But on the other hand, there might be people who mistype the parser name and get confused why they are getting segmentation fault.

My consideration of updating mpca_lang() example is to prevent some reader from giving up because they have no idea what causing the segmentation fault. But i see your point too, especially if we need to explain va_arg() and so on, the reader might get overwhelm and not continue reading instead 😅

If updating mpca_lang() example make the learning path become more convoluted, maybe we can add note "If there are some error with mpc, you can check mpc github repo" or something like that. The note i'm talking about is like this:
image

And we will leave it to the reader if they are curious enough to find out what causing the segmentation fault.

That's the solution that i can think of at the moment.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants