-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[cling] script/library support entry function independent of filename #11299
Comments
For reference, #11262 has a commit to support entry function not identical to filename. If the file is a hidden file that name starts with a dot, cling executes the function name which is same as file name but without preceding dot. |
Wouldn't an unnamed macro do the job? See attached file. The filename can be changed without having to 'rename' the main function. |
Unnamed macro is a root feature. standalone cling does not support it. In a cling test case |
No plans. But whatever the plans currently are will need to be adjusted if and once the clang patch for statements at global scope is in, as that changes the equation dramatically. |
They are reserved for implementers. Cling is an implementation, so we can totally do that :-) We actually have to do that, to avoid misinterpretation of an existing function. The attribute seems like a good alternative, though! |
Do you meaning this patch? [clang-repl] Support statements on global scope in incremental mode |
As a side note, C++ already has a notion of onload so another option could be for the user to simply use:
(and on-unload can also be done (using a class destructor for example) but requires a bit more scaffolding) |
I was not advocating for unnamed macros as alternative to what you propose here, @jiangyilism . I think @pcanal 's proposal qualifies as a (technically correct) "hack" :-) We could indeed use |
Using However that does not improve usability of However, |
@jiangyilism I am proposing to change the behavior of |
Is your feature request related to a problem? Please describe.
In cling cmd prompt,
.x
,.X
meta commands loads a.C
script then invoke a function with the same name as the script file (stripped extension).Every time the filename changes the entry function name needs to be changed too. This is not user friendly, or even error prone.
P.S. In
interpreter/cling/lib/MetaProcessor/MetaSema.cpp
, there is a comment about plan to enabling using__main__
as a filename independent entry function name. However identifier with two underscores is reserved by c++ standard (https://en.cppreference.com/w/cpp/language/identifiers).Describe the solution you'd like
A filename independent entry function like
clingmain
,clingstart
,clingrun
,cling_on_load
,cling_on_x
... etc.Or function attribute like
[[cling::on_load]] int any_func_name(char c, int a) {...}
to let cling callany_func_name
on meta cmd.x
.A
[[cling::on_unload]]
can be useful too, though not directly related to this feature request.The text was updated successfully, but these errors were encountered: