The information in this article applies to:
SYMPTOMSThe following program compiles, but one of the following warnings appears:
-or-
However, the above program will compile without exception if a type
definition is used for char* as follows:
CAUSEThis occurs for two reasons. First, typedefs are not macros, so modifiers like const or volatile apply to the whole construct. When the following are used
they are equivalent to "char* const cPtr;" not "const char* cPtr;."
Second, since "char* const cPtr;" declares cPtr as a constant pointer to character data and "const char* cPtr;" declares cPtr as a pointer to constant character data, the two declarations are quite different. Thus, a "different const qualifier" warning is generated for
because it is trying to set p equal to a pointer that points to a constant
character whose value *p could try to change. Alternatively, no warning is
generated for
because it is setting p equal to a constant pointer that points to a
character whose value *p may freely change.
REFERENCESFor more information on the const keyword, search the online documentation provided with Visual C++, 32-bit edition, for "const" or "constant values." For more information on the typedef keyword, search the online documentation for "#typedef" or "typedef specifier." Additional query words: 9.00
Keywords : kbCompiler kbVC200 kbVC210 kbVC400 kbVC500 kbVC600 |
Last Reviewed: September 16, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |