[Rcpp-devel] typedef and const
Douglas Bates
bates at stat.wisc.edu
Thu May 20 15:07:28 CEST 2010
In the process of converting code to use the Rcpp classes I discovered
that a combination of typedef and const does not work as I expected it
to work.
The background is that the C-based sparse matrix library called
CHOLMOD (used in the Matrix package for R) declares a number of C
structs such as cholmod_sparse, cholmod_dense, ... Most of the
CHOLMOD functions take pointers to these arguments and return pointers
to freshly-allocated structures. For brevity I declared typedefs like
typedef cholmod_sparse *CHM_SP;
I had thought that I could replace an argument declaration like
const cholmod_sparse *A
by
const CHM_SP A
but discovered after much experimentation that const CHM_SP A expands to
cholmod_sparse *A
In other words, I can't use const to modify a typedef as I expected.
Can someone explain why? Is there an alternative declaration that
accomplishes what I want? For the time being I have reverted to the
full declaration of const cholmod_sparse*
More information about the Rcpp-devel
mailing list