Registrations are now open. Join us today!
There is still a lot of work to do on the wiki yet! More information about editing can be found here.
Already have an account?

Microsoft KB Archive/38024

From BetaArchive Wiki
Knowledge Base


INFO: A Case Where BUFF[] and *BUFF Are Different

Article ID: 38024

Article Last Modified on 7/5/2005



APPLIES TO

  • Microsoft C Professional Development System 6.0a
  • Microsoft Visual C++ 1.0 Professional Edition
  • Microsoft Visual C++ 1.5 Professional Edition
  • Microsoft Visual C++ 1.0 Professional Edition
  • Microsoft Visual C++ 2.0 Professional Edition
  • Microsoft Visual C++ 2.1
  • Microsoft Visual C++ 4.0 Standard Edition
  • Microsoft Visual C++ 5.0 Standard Edition
  • Microsoft Visual C++ 6.0 Service Pack 5
  • Microsoft Visual C++ .NET 2002 Standard Edition
  • Microsoft Visual C++ .NET 2003 Standard Edition



This article was previously published under Q38024


NOTE: Microsoft Visual C++ NET (2002) supported both the managed code model that is provided by the .NET Framework and the unmanaged native Windows code model. The information in this article applies to unmanaged Visual C++ code only.

SUMMARY

When the variable buff has been declared in an assembly-language program, such as the following:

        .data
        public buff
_buff   db 200 dup (0xab)
        .data ends
                

there is a difference between the two following C declarations:

   extern unsigned char buff[];

   extern unsigned *buff;
                

The difference is that the first declaration says there is a block of memory that is named buff; the second says there is something called buff that is a pointer.

This difference can be seen by referencing buff as follows:

   buff[x]
                

If buff is declared as an array, the referencing is correct.

However, if buff is declared as a pointer, the referencing is incorrect. The data pointed to by buff (ab in this example) is translated into a memory address, then x bytes are added to it generating an incorrect reference.

For additional information, click the article number below to view the article in the Microsoft Knowledge Base:

44463 Difference Between Arrays and Pointers in C


Keywords: kbinfo kblangc KB38024