---
title: C6268
ms.date: 11/04/2016
ms.topic: reference
f1_keywords: ["C6268"]
helpviewer_keywords: ["C6268"]
ms.assetid: fd81e00a-de2f-498b-b3fe-53ce056042d7
---
# C6268

> warning C6268: Incorrect order of operations: (\<TYPE1>)(\<TYPE2>)x + y. Possible missing parentheses in (\<TYPE1>)((\<TYPE2>)x + y)

This warning indicates that a complex cast expression might involve a precedence problem when performing pointer arithmetic. Because casts group more closely than binary operators, the result might not be what the programmer intended. In some cases, this defect causes incorrect behavior or a program crash.

In an expression such as:

```cpp
(char *)p + offset
```

the offset is interpreted as an offset in characters; however, an expression such as:

```cpp
(int *)(char *)p + offset
```

is equivalent to:

```cpp
((int *)(char *)p) + offset
```

and so the offset is interpreted as an offset in integers. In other words, it is equivalent to:

```cpp
(int *)((char *)p + (offset * sizeof(int)))
```

which is not likely to be what the programmer intended.

Depending on the relative sizes of the two types, this can lead to a buffer overrun.

## Example

The following code generates this warning:

```cpp
void f(int *p, int offset_in_bytes)
{
    int *ptr;
    ptr = (int *)(char *)p + offset_in_bytes;
    // code ...
}
```

To correct this warning, use the following code:

```cpp
void f(int *p, int offset_in_bytes)
{
    int *ptr;
    ptr = (int *)((char *)p + offset_in_bytes);
    // code ...
}
```
