Skip to content

Files

Latest commit

 

History

History
25 lines (16 loc) · 730 Bytes

runtime-memset.md

File metadata and controls

25 lines (16 loc) · 730 Bytes

Pattern: Wrong use of memset()

Issue: -

Description

Use sizeof(varname) when you take the size of a particular variable. sizeof(varname) will update appropriately if someone changes the variable type either now or later. You may use sizeof(type) for code unrelated to any particular variable, such as code that manages an external or internal data format where a variable of an appropriate C++ type is not convenient.

Example of incorrect code:

Struct data;
memset(&data, 0, sizeof(Struct));

Example of correct code:

Struct data;
memset(&data, 0, sizeof(data));

Further Reading