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

$INCLUDE_ONCE #240

Closed
grymmjack opened this issue Nov 7, 2022 · 2 comments · Fixed by #448
Closed

$INCLUDE_ONCE #240

grymmjack opened this issue Nov 7, 2022 · 2 comments · Fixed by #448
Labels
enhancement New feature or request

Comments

@grymmjack
Copy link
Contributor

It would be fantastic if we had a pre-compiler statement that made sure the file being $INCLUDEd is only included once.

In C this is #pragma once I believe.

Why would it help?

We could avoid having to handle our own defines all over our code.

Here is an example of where I have had to implement my own include "guards":

Once at the top of the file for the .BI:

$IF GJ_LIB_ANSI_INC_BI = UNDEFINED THEN
'$INCLUDE:'ANSI.BI'
$END IF

From: https://github.com/grymmjack/QB64_GJ_LIB/blob/ad1a293001575a705daf718a6d68da79ec4c2f58/ANSI/ANSI.BAS#L13

Then at the bottom of the file for the .BM:

$IF GJ_LIB_ANSI_INC_BM = UNDEFINED THEN
'$INCLUDE:'ANSI.BM'
$END IF

https://github.com/grymmjack/QB64_GJ_LIB/blob/ad1a293001575a705daf718a6d68da79ec4c2f58/ANSI/ANSI.BAS#L793

I know this is an extreme case, but my library could be cleaned up quite a bit if we just had a feature like this.

Thanks for listening!

@mkilgore mkilgore added the enhancement New feature or request label Nov 7, 2022
@a740g
Copy link
Contributor

a740g commented Nov 7, 2022

My suggestion would be to let the legacy '$INCLUDE: metacommand stay the way it is. Instead, we can have a QB64 style metacommand $INCLUDEONCE: to include files only once. Alternately, we can do it like most modern C++ compilers do it with #pragma once. So, we can have the meta command like $INCLUDEONCE which when detected would ignore the file if it were already included.

@grymmjack
Copy link
Contributor Author

@RhoSigma-QB64 Thank you for implementing this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Development

Successfully merging a pull request may close this issue.

3 participants