TICS Coding Standard Viewer 
TIOBE Software Quality Framework
Print-friendly version
©TIOBE Software www.tiobe.com
C++ Coding Standard

Rule:  CON#008Checked automatically with code checker

This rule is Obsolete
Synopsis:Don't take the address of an array
Severity Level:1


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