-
-
Notifications
You must be signed in to change notification settings - Fork 171
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
Feature request: #pragma once
or include_once
equivalent
#1478
Comments
This is in theory possible, but That said, it's used in C because forward-decls are often necessary, and thus headers can end up referring to each other. This hardly ever happens in assembly AFAICT, so do you have a particular counter-example in mind? |
We could also go for an Prior art: PHP ( |
Yes, I do have an example. I use include files to define constants and macros, that I need to reach from multiple files. This creates the same problem as exists in C, where the functions (in this case, the macros or constants) have to be forward declared |
|
Out of two popular I'd like to get more gbdev users' feedback on this proposal, see how in-demand this would be. |
Re: symlinks and hard links, if we added an |
But such files only need each (And, constants can be exported in many cases, too, FWIW.) |
Yes, you are right, that is why I want the include guard. I have had situations where I define a macro in one I guess it comes down to how I like to structure my projects. I would rather explicitly include a header, than have it implicitly included by another header. The existance of |
#pragma once
equivalent#pragma once
or include_once
equivalent
Guess what hurdle I just managed to overcome thanks to WSL! I look forward to hearing your feedback! |
Could you link to a project that would benefit from it, please? We must balance two things: how useful the feature would be to other projects, and the cost for us to maintain it. I do appreciate the effort you've put into the PR (that you've set up a dev env, added some testing...), but it's a burden for the maintainers (the more code we have, the more has potential to break, and the more we have to update when making some internal changes, for example). This is why we want every new feature to clear an (arguably fuzzy) “minimum added value” bar. If you can show us a kind of project that suffers from the lack of this feature, that would help us gauge that further. Thanks! |
Apparently esprit could benefit; some of its includes have C-style header guards. (Of course, the whole project's conventions for including things could be refactored to avoid that need, e.g. by copying pokecrystal or gb-starter-kit and having one file responsible for including everything you might need; but that would be a reason to close this feature request outright as "can technically be worked around".) |
Also if pokecrystal ends up doing something like pret/pokecrystal#631, then I expect |
I have one of my own projects, not sure if that counts: https://github.com/sukus21/towizz Not all of the included files have guards, as it only really became a problem for me later in development. Most files in |
Sorry, but after discussing this further, we've decided it's too fragile to support cross-platform after all. (A bit similar to C's |
I haven't had a chance to explain the rationale more in depth, so please allow me to: I think there is a major split between a file (as in, the object itself) and its contents. Thus far, RGBASM has used the contents exclusively. Except that paths are used for The major difference I see with
Ultimately, I recognise the feature's goals and usefulness, but I feel like they do not balance out the concerns above. This is what I have tried to express above, during the limited time I've been able to devote to RGBDS during my past weeks of holidays. (Please remember, this is not my job!) I also understand that the implementation is simple, but I would like to respectfully point out that this simplicity may be hiding a lot of complexity—complexity that, if it doesn't deal with itself, is pushed onto the end user. This is why I've asked for this feature request to be rejected. I hope it makes sense, and that you'll understand. |
Include guards are a common problem in languages with include files. In some C/C++ compilers, the problem is remedied by supporting the
#pragma once
precompiler directive. I would like to suggest that RGBDS implements a feature similar to this. I will be reffering to it aspragma once
throughout this issue, even though I don't necessarily think that should be what it's called in RGBDS (it could be called something likeINCGUARD
?).My assumption is that RGBASM keeps track of the name of the file it is currently processing. There could be a table somewhere keeping track of files that have been
#pragma once
'd. Whenever the directive is hit, check if the current file is in the table. If it is not in the table, add it and keep processing it. If it is in the table, don't include the rest of the files content from that point forward.Keep in mind I have no clue how possible it is to implement this. I am not familiar with the RGBDS codebase, and my attempts to build it by hand have been futile so far. I hope this will be considered :)
The text was updated successfully, but these errors were encountered: