- 
                Notifications
    You must be signed in to change notification settings 
- Fork 472
Pragma once #2353
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
base: master
Are you sure you want to change the base?
Pragma once #2353
Conversation
Makes so that preprocessing a pragma yields a status flag with additional information on how to handle that particular #pragma. Mostly a prepraration for #pragma once.
| a bit of an anti-feature, as using it makes your code no longer conformant to C, but if it is to be implemented, it would be more elegant to just add a hidden macro like  | 
| 
 Hmm I don't get it, to be honest. Would the macro be added as the output of the preprocessor? | 
| 
 no, it would just generate the macro and add it to the list of other defined macro while passing over a sourcefile, as if the user had written instead of  | 
| I see, but I still believe we would have to find the absolute path of the file anyway (e.g to generate the macro name), | 
| it should be sufficient to use the basename of the file, unless there's more than one file of the same name... to support this, you indeed need to use either the complete, normalized filename to generate a unique macro, or a cryptographic hash of the file contents (assuming the preprocessor code has access to the entire file contents from top to bottom during the processing of single lines). if pragma == "once":
  s = generate_unique_macro_based_on_filename(filename)
  if not s in macros:
    macros[s] = 1
  else:
    stop_preprocessing_current_file() | 
| Oh I get it now. I was a bit confused since you said "instead of doing path shenanigans", and thought the problem was getting the full path for things. I assume you meant "instead of doing strpool shenanigans" instead? | 
| I think if someone wants to roll out a #pragma once, the first thing to do is to define which heuristic will be used to assume it is the same file? Afterwards, this heuristic has to be implemented. The problems with symlinks, hardlinks and hand-copied files are known, and it is not trivial to define it, because most views are valid from the one or the other perspective. | 
| 
 no, i assumed taking the basename() of the file would be sufficient - i didn't think about the case of multiple files of the same basename, each using the pragma. it's generally confusing and bad practice to have several headers with the same filename (in different dirs though), but it might happen in complex projects with library code in subdirs. even then, one would assume the subprojects use proper include guards for portability instead of the microsoft-ish pragma once. | 
| 
 Alright. So, this is what I plan to implement in this PR: 
 For linux, the 2008 POSIX revision of  However, I am still unsure on what to do to determine whether the to-be-included file has been seen with  I think the most straightforward solution is to use a  | 
| 
 For hard links you also need to look at the inode and device numbers. What problem does this PR solve? | 
| 
 This PR does not intend to solve an existing problem in cc65, but instead to implement the  
 My bad. Trying to get it to behave like gcc and clang would be great, but maybe it's a bit overkill to check hard links as well? What do you think? | 
Pragma once checking now happens in #include
| PR StatusThis pull request currently implements #pragma once, as described in an earlier comment, except it does not consider file and filesystem IDs for hard links. I can implement it if it is desirable, but I'd like to get some feedback on what is implemented so far. | 
| since you ask for a review i judge by this metric:  | 
| I appreciate your constructive criticism. Is this sentiment towards this implementation/feature shared between other collaborators? With regard to the macro table, I've been avoiding touching it so far, because storing absolute file names in it sounds hacky to me, but if that's seem as acceptable, I'll have no problem adapting this into the pull request. | 
| I'm not a pragma once fan at all, but the PR size doesn't matter.…  Message ID: ***@***.***>
 | 
| OK so, i was holding back with commenting, because i wanted to hear some other opinions first. First of all, some nitpicking on the PR itself: 
 Now for: 
 I have to admit that i am not a fan of this extension, nor do i see a point in using it at all. Like rofl0r said, this is a rather huge change, for something that's not even a standard feature. I have my doubts that it would save anyone as much typing as what went into this PR :) I also think the "convert into macro" solution is the better one (and you can eg encode pathes into BASE64 - or even just plain hex codes - to get rid of problems with special characters). Because of this i am also leaning towards "don't merge" right now. I'd like to hear opinions from other contributors however, like @oliverschmidt @acqn | 
| As I'm explicitly asked: My personal opinion is to not merge this PR. | 
| Well, thank you all for the time invested. I'd like to have some clarification on some things. 
 The following questions depend on the answer of 1. being positive, for a future reference in case anybody tries to implement it. 
 | 
| @cosineblast: Just my two cents as former maintainer: Yes, if you implement an open feature request any your implementation has no obvious flaws then you should be able to assume that your implementation is welcome. Period. Why isn't it like this? Because "weird" feature requests aren't closed. Why aren't "weird" feature requests not closed? Because closing a feature request results in lengthy discussions the maintainer wants to avoid. Is there a way to avoid this situation in the future? My personal(!) proposal is to add a boilerplate comment to all open feature requests saying something alone the lines of "If you consider to close this feature request by actually implementing the feature requested, then please get in touch with the maintainer before investing any effort." | 
| fair enough | 
| I have added a note about this in https://github.com/cc65/cc65/blob/master/Contributing.md instead (which i expect anyone to read before starting anyway) | 
| I plan on working on this PR in a near future, with the goal of changing the file verification mechanism so that it uses the macro table. 
 Before going on with things, I'd like to ask which of these options would be more suitable (or another alternative I didn't think of). For ease of explanation, I will refer to the former approach as the  I was planning on going with the  I was just going to keep going with the  | 
| I would certainly prefer whatever requires less changes/additions in the compiler. I cant say which it is however. I'd also prefer a solution that doesn't require OS specific hackery (but i don't think it can work without in practise). | 
| at the risk of reigniting a flame war, this seems a little complex. why not, before inclusion, scan the file for a "#pragma once". if it has one, checksum the file. if the checksum matches something else already included as a pragma once, skip the include. what's all this argument about paths and hidden macros ? | 
| The main issue is that I was trying to go for the same behaviour as mainstream compilers, which was a bit overkill for the scope of cc65 | 
| A few comments since this came up in #2743. It is not only important to define heuristics regarding "same file" semantics. The  very first thing would be to define what  So, should  This might be used as If  If   | 
Fixes #1596.
This implements a
#pragma oncedirective in the C preprocessor.This is achieved by finding the absolute of the current file (using
GetFinalPathNameByHandleAon windows and POSIX 2008realpathon other platforms) and saving it in aStringPool.