Unicorn with delicious cookie
Nous utilisons des cookies pour améliorer votre expérience de navigation. En savoir plus
Accepter
to the top
>
>
>
V569. Truncation of constant value.
menu mobile close menu
Additional information
toggle menu Contents

V569. Truncation of constant value.

23 Jui 2011

The analyzer detected a potential error: a constant value is truncated when it is assigned into a variable.

Consider this sample:

int A[100];
unsigned char N = sizeof(A);

The size of the 'A' array (in Win32/Win64) is 400 bytes. The value range for unsigned char is 0..255. Consequently, the 'N' variable cannot store the size of the 'A' array.

The V569 warning tells you that you have chosen a wrong type to store this size or that you actually intended to calculate the number of items in the array instead of the array's size.

If you have chosen a wrong type, you may correct the code this way:

size_t N = sizeof(A);

If you intended to calculate the number of items in the array, you should rewrite the code this way:

unsigned char N = sizeof(A) / sizeof(*A);

This diagnostic is classified as:

You can look at examples of errors detected by the V569 diagnostic.