This rule is Obsolete | |
Synopsis: | Don't take the address of an array |
Language: | C++ |
Severity Level: | 1 |
Category: | Conversions |
Description: |
One should take care that an array variable is a pointer to the first element of the array. This can lead to subtle unintended incorrect usage and crashes as shown in the example below: const DWORD mv_dwReadEventLogBufferSize = 64 * 1024; // All records from the event log can be read now. BYTE abyBuffer[mv_dwReadEventLogBufferSize]; // EVENTLOGRECORD defined in winnt.h // Compiles fine but is wrong. Variable 'pEventLogRecord' contains one indirection too many. EVENTLOGRECORD* pEventLogRecord = (EVENTLOGRECORD*) &abyBuffer; It should have been as follows (two choices): EVENTLOGRECORD* pEventLogRecord = (EVENTLOGRECORD*) abyBuffer; // OK EVENTLOGRECORD* pEventLogRecord = (EVENTLOGRECORD*) &abyBuffer[0]; // OK |