Skip to content
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

[FIX] Resolve questions about function pointer cast to (void *) + some standardization #40

Merged
merged 8 commits into from
Dec 27, 2023

Conversation

itislu
Copy link
Sponsor Collaborator

@itislu itislu commented Dec 23, 2023

The necessity for the (void *) typecasting was caused by the function declarations of the functions expecting function pointers.

If a function expects a function ptr which argument is (void *), the argument of the function that gets passed as a function ptr also needs to be of type (void *).
Otherwise, typecasting is needed - and weirdly this is done in front of the function ptr.

What this means going forward:

Whenever we have to typecast a function pointer to (void *), it means we should be careful what types we pass to this function pointer because it can only handle a certain type.


Other improvements:

  • Make use of libft functions for freeing and remove unnecessary NULL checks.

  • Standardize cur variable name (replacing last remaining instance of curr).

  • Protect against segfault in get_state_from_stack() function.

  • Remove NULL checks before ft_free_and_null() because it checks by itself.

  • Instead of (void *) arguments, specify for all free functions what types they can free.

  • Standardize NO space after typcasting.

@itislu itislu added the enhancement Enhancement of an existing feature label Dec 23, 2023
@itislu itislu linked an issue Dec 23, 2023 that may be closed by this pull request
@itislu itislu changed the title [FIX] Fix function pointer cast to (void *) [FIX] Fix necessity of function pointer cast to (void *) Dec 25, 2023
@itislu
Copy link
Sponsor Collaborator Author

itislu commented Dec 25, 2023

Actually, I'm not so sure anymore if generalising free-functions like free_ast_data() and removing the need to typecast the function pointers to (void *) is a good idea.

It bypasses the type safety provided by the compiler, which is bad because these functions can only handle a specific type of argument correctly.

@LeaYeh Let's please discuss this on campus before merging.

@itislu itislu changed the title [FIX] Fix necessity of function pointer cast to (void *) [FIX] Resolve questions about function pointer cast to (void *) + some standardization Dec 26, 2023
@itislu itislu requested a review from LeaYeh December 26, 2023 21:06
@LeaYeh LeaYeh merged commit a917143 into main Dec 27, 2023
1 check passed
@itislu itislu deleted the fix-function-ptr-cast branch December 27, 2023 14:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Enhancement of an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[QUESTION] Why do some function ptrs need (void *) typecasting?
2 participants