[Rcpp-devel] Is the order of initializations within a data type defined?
bates at stat.wisc.edu
Wed Mar 24 21:26:09 CET 2010
On Wed, Mar 24, 2010 at 2:47 PM, Dirk Eddelbuettel <edd at debian.org> wrote:
> On 24 March 2010 at 13:31, Douglas Bates wrote:
> | I find myself writing code like
> | Rcpp::NumericVector mu(arg);
> | Rcpp::NumericVector eta(mu.size());
> | ...
> | because I need to ensure that mu is constructed from the argument SEXP
> | before its size can be used to construct eta. Is the order of
> | initializations compiler-dependent or defined by the standard? If
> | defined by the standard I could write
> | Rcpp::NumericVector mu(arg), eta(mu.size());
> | and expect it to work as intended. Does anyone know if I can count on
> | left-to-right ordering of initializations?
> Interesting question, and I can't offer more than a firm 'not sure'. You
> could for now put some of our conditional logging in the constructor as some
> other classes (that take a string as well and then print that string, say) so
> that you could at least test with the compiler you happen to using today.
> Strictly personally speaking I quite like
> Rcpp::NumericVector mu(arg);
> Rcpp::NumericVector eta(mu.size());
> as it gives me ample space to the right comment.
Agreed. However I have been trained by Martin Maechler never to use
cut-and-paste when programming (Knuth's "root of all evil" is
premature optimization and Martin's is cut-and-paste) so I feel like a
sinner every time I duplicate a line then change the identifier.
More information about the Rcpp-devel