-
-
Notifications
You must be signed in to change notification settings - Fork 208
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 invalid C++ identifiers #387
Comments
Thanks for the note, Konrad. That is attributes.cpp only and hence well localised. I would encourage you (as the one with an itch to scratch) to work on a pull request if you want to see change "soon" as we all are a tad too busy to write code on demand for what I'd call non-bugs. We effectively live in a g++/clang++ world only even though the occasional user may edploy the Intel compiler or work on some non-standard OS besides Windoof, OS X and Linux. And in that world this just doesn't seem to have bitten so shrugs ... |
We used those prefixes specifically because they are reserved for the On Fri, Oct 30, 2015 at 12:09 PM, Dirk Eddelbuettel <
|
@jjallaire I agree that a prefix is entirely appropriate (and arguably even necessary) here. I can try my hand at a PR. |
I read the comment differently from you, @klmr :
Looks like we're not yet convinced we need it but heck, if you submit something we will look at it. |
@eddelbuettel I got that part, but the “compilation” done by Rcpp isn’t part of the C++ standard compilation workflow so its use of |
Understood, but with C++11 attributes are often used as code generators On Fri, Oct 30, 2015 at 1:55 PM, Konrad Rudolph notifications@github.com
|
We could also hide the implementation in a separate namespace, e.g. CharacterVector fun(RObject data);
namespace Rcpp {
namespace generated {
inline SEXP pkg_fun(SEXP dataSEXP) {
// impl
}
}
}
RcppExport SEXP pkg_fun(SEXP dataSEXP) {
return Rcpp::generated::pkg_fun(dataSEXP);
} Or, just consider using e.g. an |
In this particular case I think none of these options are technically necessary since it’s an isolated compilation unit and scope (except that it needs to avoid clashing with function parameters, of course). In general, though, the idea of using a prefix is to avoid name clashes with global macros — even if that shouldn’t happen here it’s probably a good policy. |
While I'm in the (Tagging #506) |
Yes. And change every include guard to single underscores while you're at it. |
Or better yet #pragma once |
I don't know #pragma once is going to work on every compiler we end up On Mon, Aug 1, 2016 at 8:15 PM, Daniel C. Dillon notifications@github.com
|
@jjallaire took the words from my mouth as I was transcribing them. I'm planning on also modifying: std::string CppPackageIncludeGenerator::getHeaderGuard() const {
return "__" + packageCpp() + "_h__";
} |
Heh. Well single underscores and an RCPP prefix would be best |
At any rate a good rule of thumb I have found for include guards is PACKAGE_NAMESPACE_NAMESPACE_NAMESPACE_FILE_H |
Technically, all identifiers even containing two underscores are considered reserved by the C++ standard, so we shouldn't use those either. From http://stackoverflow.com/questions/228783/what-are-the-rules-about-using-an-underscore-in-a-c-identifier:
Isn't C++ fun? :) But let's not bikeshed ourselves into oblivion... |
In favour of
as there is no identified problem with them. Ditto against
as I don't buy into change for change's sake. |
I can tell you that #pragma once, while not technically portable, is pretty much industry standard. That being said, industry doesn't use joeschickenandcppcompiler because it has the a license that permits use while ice fishing with natives of the tropics. |
So, to conclude, go with the prefix of: RCPP_ # option 1
RCPP_CORE_ # option 2 Skip the suffix/postfix of Make sure there are no |
I like option 1 and it is machine generated why not add |
For posterity the invalid identifier are.... (drum roll...) Variables
FunctionsFrom: std::string CppPackageIncludeGenerator::getHeaderGuard() const {
return "__" + packageCpp() + "_h__";
} To: std::string CppPackageIncludeGenerator::getHeaderGuard() const {
return "RCPP_" + packageCpp() + "_h_gen_";
} From: std::string CppExportsIncludeGenerator::getHeaderGuard() const {
return "__" + packageCpp() + "_RcppExports_h__";
} To: std::string CppExportsIncludeGenerator::getHeaderGuard() const {
return "RCPP_" + packageCpp() + "_RcppExports_h_gen_";
} |
Is it just me or does anybody else think that Variables
might be nicer? |
Yes, I'd agree that lower case is nicer here (and without the trailing On Tue, Aug 2, 2016 at 6:19 AM, Dirk Eddelbuettel notifications@github.com
|
@eddelbuettel : Please close this as it was apart of PR #528 . It looks like automatic only works on 1 issue id at a time? (Tagging #506). |
Rcpp uses
__
as a prefix for identifiers in auto-generated code (e.g. here and here). This is problematic, since__
is not not valid in C++ identifiers (it’s reserved for use by the compiler).Such identifiers are for instance used by standard library implementations. And although most modern implementations try to avoid aggravating users, and so use more explicit conventions in their macro names, a simple grep through the libc++ implementation shows a few macros with names such as
__need_size_t
(and more in libstdc++), so it’s not unthinkable that there might be conflicts with future versions of some compilers.It would be better to replace these instances with a legal identifier token, e.g.
Rcpp_
.The text was updated successfully, but these errors were encountered: