One of my colleagues has recently said that the above statement is not type safe and I should use something else as you need as much type safe structures as possible to reduce the amount of possible bugs.
Whilst I agree on being type safe, I'm a little confused as this is the type of code in question (only the contents and length of data[] is modified)
unsigned char data[] = {1,2,3,4,5};
int data_len = sizeof(data) / sizeof(data[0]);
Where is the part that is not type safe?
Needless to say, other than the comment, the colleague will not explain further.
PS: This is used to copy initialisation data into a class from the constructor, no C++11 compiler exists here, so we can't use std::array or other fancy array initialisation. techniques.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…