[Rcpp-devel] Is the order of initializations within a data type defined?

Romain Francois romain at r-enthusiasts.com
Wed Mar 24 22:20:16 CET 2010


Le 24/03/10 21:26, Douglas Bates a écrit :
>
> 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.

I think , is left to right. We actually use this when we do:

IntegerVector x(3) ;
x = 1,2,3;

see maybe this : http://www.cppreference.com/wiki/operator_precedence

I'm not sure I'd want to trust this though.

Romain

-- 
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://tr.im/OIXN : raster images and RImageJ
|- http://tr.im/OcQe : Rcpp 0.7.7
`- http://tr.im/O1wO : highlight 0.1-5



More information about the Rcpp-devel mailing list