R_ext/Altrep.h should be more C++-friendly

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

R_ext/Altrep.h should be more C++-friendly

R devel mailing list
I am not able to #include "R_ext/Altrep.h" from a C++ file.  I think
it needs two changes:

1. add the same __cplusplus check as most of the other header files:
    #ifdef  __cplusplus
    extern "C" {
    #endif
        ...
    #ifdef  __cplusplus
    }
    #endif

2. change the line
    R_new_altrep(R_altrep_class_t class, SEXP data1, SEXP data2);
 to
    R_new_altrep(R_altrep_class_t cls, SEXP data1, SEXP data2);
 since C++ doesn't like an argument named 'class'

  ~~ Michael Sannella

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: R_ext/Altrep.h should be more C++-friendly

Tierney, Luke
Thanks for the suggestion. Committed in R_devel.

Best,

luke

On Mon, 8 Oct 2018, Michael Sannella wrote:

> I am not able to #include "R_ext/Altrep.h" from a C++ file.  I think
> it needs two changes:
>
> 1. add the same __cplusplus check as most of the other header files:
>     #ifdef  __cplusplus
>     extern "C" {
>     #endif
>         ...
>     #ifdef  __cplusplus
>     }
>     #endif
>
> 2. change the line
>     R_new_altrep(R_altrep_class_t class, SEXP data1, SEXP data2);
>  to
>     R_new_altrep(R_altrep_class_t cls, SEXP data1, SEXP data2);
>  since C++ doesn't like an argument named 'class'
>
>   ~~ Michael Sannella
>
>
>

--
Luke Tierney
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa                  Phone:             319-335-3386
Department of Statistics and        Fax:               319-335-3017
    Actuarial Science
241 Schaeffer Hall                  email:   [hidden email]
Iowa City, IA 52242                 WWW:  http://www.stat.uiowa.edu
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: R_ext/Altrep.h should be more C++-friendly

Gabe Becker
In reply to this post by R devel mailing list
Michael,

Thanks for reaching out. This was brought up by Romaine Francois offline to
me as well. What he does as a workaround is


#define class klass
extern "C" {
  #include <R_ext/Altrep.h>
}
#undef class

While we consider changing Altrep.h, the above should work for you  in the
immediate term.

Let me know if it doesn't.

~G





On Mon, Oct 8, 2018 at 4:17 PM, Michael Sannella via R-devel <
[hidden email]> wrote:

> I am not able to #include "R_ext/Altrep.h" from a C++ file.  I think
> it needs two changes:
>
> 1. add the same __cplusplus check as most of the other header files:
>     #ifdef  __cplusplus
>     extern "C" {
>     #endif
>         ...
>     #ifdef  __cplusplus
>     }
>     #endif
>
> 2. change the line
>     R_new_altrep(R_altrep_class_t class, SEXP data1, SEXP data2);
>  to
>     R_new_altrep(R_altrep_class_t cls, SEXP data1, SEXP data2);
>  since C++ doesn't like an argument named 'class'
>
>   ~~ Michael Sannella
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
>


--
Gabriel Becker, Ph.D
Scientist
Bioinformatics and Computational Biology
Genentech Research

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: R_ext/Altrep.h should be more C++-friendly

Romain Francois-3
I successfully use this workaround in this package: https://github.com/romainfrancois/altrepisode

(which is just my way to get familiar with altrep, nothing serious)

> Le 9 oct. 2018 à 17:00, Gabe Becker <[hidden email]> a écrit :
>
> Michael,
>
> Thanks for reaching out. This was brought up by Romaine Francois offline to me as well. What he does as a workaround is
>
>
> #define class klass
> extern "C" {
>   #include <R_ext/Altrep.h>
> }
> #undef class
>
> While we consider changing Altrep.h, the above should work for you  in the immediate term.
>
> Let me know if it doesn't.
>
> ~G
>
>
>
>
>
>> On Mon, Oct 8, 2018 at 4:17 PM, Michael Sannella via R-devel <[hidden email]> wrote:
>> I am not able to #include "R_ext/Altrep.h" from a C++ file.  I think
>> it needs two changes:
>>
>> 1. add the same __cplusplus check as most of the other header files:
>>     #ifdef  __cplusplus
>>     extern "C" {
>>     #endif
>>         ...
>>     #ifdef  __cplusplus
>>     }
>>     #endif
>>
>> 2. change the line
>>     R_new_altrep(R_altrep_class_t class, SEXP data1, SEXP data2);
>>  to
>>     R_new_altrep(R_altrep_class_t cls, SEXP data1, SEXP data2);
>>  since C++ doesn't like an argument named 'class'
>>
>>   ~~ Michael Sannella
>>
>>         [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> [hidden email] mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>
>
>
>
> --
> Gabriel Becker, Ph.D
> Scientist
> Bioinformatics and Computational Biology
> Genentech Research

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: R_ext/Altrep.h should be more C++-friendly

Romain Francois-3
In reply to this post by Tierney, Luke
Thank you,

I updated my example package so that it works with both. https://github.com/romainfrancois/altrepisode/blob/96af0548a9ecc08701d119ea427e16940a82882b/src/altrepisode.h <https://github.com/romainfrancois/altrepisode/blob/96af0548a9ecc08701d119ea427e16940a82882b/src/altrepisode.h>

We have to do something like this unless we depend on R 3.6.0:

#if R_VERSION < R_Version(3, 6, 0)
  #define class klass
  extern "C" {
    #include <R_ext/Altrep.h>
  }
  #undef class
#else
  #include <R_ext/Altrep.h>
#endif

Romain

> Le 9 oct. 2018 à 05:09, Tierney, Luke <[hidden email]> a écrit :
>
> Thanks for the suggestion. Committed in R_devel.
>
> Best,
>
> luke
>
> On Mon, 8 Oct 2018, Michael Sannella wrote:
>
>> I am not able to #include "R_ext/Altrep.h" from a C++ file.  I think
>> it needs two changes:
>>
>> 1. add the same __cplusplus check as most of the other header files:
>>     #ifdef  __cplusplus
>>     extern "C" {
>>     #endif
>>         ...
>>     #ifdef  __cplusplus
>>     }
>>     #endif
>>
>> 2. change the line
>>     R_new_altrep(R_altrep_class_t class, SEXP data1, SEXP data2);
>>  to
>>     R_new_altrep(R_altrep_class_t cls, SEXP data1, SEXP data2);
>>  since C++ doesn't like an argument named 'class'
>>
>>   ~~ Michael Sannella
>>
>>
>>
>
> --
> Luke Tierney
> Ralph E. Wareham Professor of Mathematical Sciences
> University of Iowa                  Phone:             319-335-3386
> Department of Statistics and        Fax:               319-335-3017
>    Actuarial Science
> 241 Schaeffer Hall                  email:   [hidden email]
> Iowa City, IA 52242                 WWW:  http://www.stat.uiowa.edu
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel


        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel