다음을 통해 공유


PREfast Warning 260 (Windows CE 5.0)

Send Feedback

260 - Sizeof * Sizeof is almost always wrong.
Additional Information: <value1> * <value2>.
Question: Was a character count or byte count intended?

This warning indicates that the results of two sizeof operations have been multiplied together.

The C/C++ sizeof operator returns the number of bytes of storage an object uses. It is typically incorrect to multiply it by another sizeof.

In C, the type of a character literal is int. Therefore, sizeof('\0') == 4

In C++, the type of a character literal is char. Therefore, sizeof('\0') == 1

In both C and C++, the following holds:

sizeof ("\0") == 2. 

Example

Defective Source

int a;
a = sizeof (L"String") * sizeof (WCHAR);

Corrected Source

int a;
// To get characters in string: 
a = sizeof (L"String") / sizeof (WCHAR);
// To get bytes string:
a = sizeof (L"String");

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.