Q51613: The /Gm Switch Really Does Move Constants to _CONST
Article: Q51613
Product(s): See article
Version(s): 5.10 | 5.10
Operating System(s): MS-DOS | OS/2
Keyword(s): ENDUSER | | mspl13_c
Last Modified: 20-DEC-1989
Question:
I am using the /Gm switch to move near string constants into the
_CONST segment, but it doesn't seem to work properly. My program is
shown below:
char foo[] = "hello";
void main(void)
{
}
When I examine the map file generated, it tells me that foo is stored
in _DATA. Why isn't the string constant "hello" being stored in
_CONST?
Response:
The /Gm switch is behaving as it should. In the above case, the string
constant "hello" is not stored as a constant, it is merely a shorthand
way of initializing the array foo. For example,
char foo[] = "hello";
is equivalent to saying the following:
char foo[] = {'h','e','l','l','o','\0'};
The data in the array foo is not a string constant, and therefore,
should not be moved to the _CONST section with the /Gm switch.
The following code demonstrates a few string constants:
#include <stdio.h>
void main(void)
{
char array[] = "This is NOT a string constant.";
char *foo = "This would be moved out to _CONST with /Gm";
printf("This string will be moved to _CONST\n");
}
THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.
Copyright Microsoft Corporation 1986-2002.