You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: "Learn more about: Warning C6396: sizeof('integerConstant') always returns the size of the underlying integer type"
3
+
title: Warning C6396
4
+
ms.date: 02/05/2024
5
+
f1_keywords: ["C6396", "SIZEOF_CONSTANT"]
6
+
helpviewer_keywords: ["C6396"]
7
+
---
8
+
# Warning C6396
9
+
10
+
> sizeof('integerConstant') always returns the size of the underlying integer type
11
+
12
+
## Remarks
13
+
14
+
This warning indicates where an integral constant is used as a `sizeof` argument. Such expression always returns the size of the type of the constant. It's better to write `sizeof(type)` instead. This warning catches common typos in buffer offset calculations.
15
+
16
+
This check ignores character literals because `buffer_size += sizeof(UNICODE_NULL)` is a common idiom.
17
+
18
+
## Example
19
+
20
+
```cpp
21
+
voidf()
22
+
{
23
+
int a = sizeof(5); // C6396 reported here
24
+
}
25
+
```
26
+
27
+
To fix this issue, replace the integral constant with its type:
description: "Learn more about: Warning C6397: The address-of operator cannot return null pointer in well-defined code"
3
+
title: Warning C6397
4
+
ms.date: 02/05/2024
5
+
f1_keywords: ["C6397", "DUBIOUS_NULL_CHECK"]
6
+
helpviewer_keywords: ["C6397"]
7
+
---
8
+
# Warning C6397
9
+
10
+
> The address-of operator cannot return `null` pointer in well-defined code
11
+
12
+
## Remarks
13
+
14
+
The address-of operator returns the address of its operand. This value should never be compared to `nullptr`:
15
+
* The address-of a field can only be `nullptr` if the base pointer was `nullptr` and the field is at the zero offset (`&p->field == nullptr` implies `p == nullptr`). In this case, the expression should be simplified.
16
+
* In any other cases, the value of the unary `&` operator can't be `nullptr` unless there's undefined behavior in the code (`&v == nullptr` always evaluates to false).
17
+
18
+
## Example
19
+
20
+
```cpp
21
+
boolisNull(int *a)
22
+
{
23
+
return &a == nullptr; // C6397 reported here.
24
+
}
25
+
```
26
+
27
+
To fix this issue, double check if the use of unary `&` was intentional:
> The address-of a field cannot be `null` in well-defined code
11
+
12
+
## Remarks
13
+
14
+
The address-of operator returns the address of its operand. This value should never be compared to `nullptr`:
15
+
* The address-of a field can only be `nullptr` if the base pointer was `nullptr` and the field is at the zero offset (`&p->field == nullptr` implies `p == nullptr`). In this case, the expression should be simplified.
16
+
* In any other cases, the value of the unary `&` operator can't be `nullptr` unless there's undefined behavior in the code (`&v == nullptr` always evaluates to false).
17
+
18
+
## Example
19
+
20
+
```cpp
21
+
structA { int* x; };
22
+
23
+
bool hasNullField(A *a)
24
+
{
25
+
return &a->x == nullptr; // C6398 reported here.
26
+
}
27
+
```
28
+
29
+
To fix this issue, double check if the use of unary `&` was intentional:
30
+
31
+
```cpp
32
+
struct A { int* x; };
33
+
34
+
bool hasNullField(A *a)
35
+
{
36
+
return a->x == nullptr; // no C6398 reported here.
0 commit comments