BUG: C2446 Assigning Pointer to Array in Named Section
PSS ID Number: Q107430
Article last modified on 07-27-1994

8.00

WINDOWS NT


----------------------------------------------------------------------
The information in this article applies to:

 - Microsoft C/C++ Compiler for Windows NT, version 8.0, (included with
   Visual C++ for Windows NT, version 1.0)
----------------------------------------------------------------------

SYMPTOMS
========

Attempting to assign a pointer to an array allocated and initialized
in a section specified with #pragma data_seg produces the error:

   error C2446: '=' : no conversion from 'char [n]' to 'char *'

RESOLUTION
==========

To eliminate the error, explicitly cast the array to the type of the
pointer.

STATUS
======

Microsoft has confirmed this to be a problem with Microsoft C/C++
version 8.0 that ships with Visual C++ for Windows NT, version 1.0.
We are researching this problem and will post new information here in the
Microsoft Knowledge Base as it becomes available.

MORE INFORMATION
================

Normally, the compiler treats an array name and a pointer to the same
data type as the array's base type as synonymous. For example the
following code compiles with no errors or warnings:

   char* szPtr;
   char szArray [10];

   szPtr = szArray;

In Visual C++ for Windows NT, when the #pragma data_seg is used to
allocate an array to a specified section, the compiler generates a
C2446 error message as though the two were not equivalent. The sample
code below demonstrates that the error occurs when the array is
allocated to another section.

With the 16-bit compiler, the data_seg pragma refers to segments;
however, there are no actual segments with 32-bit code. Instead, there
are sections that can be thought of as logical segments.

Sample Code
-----------

/* Compile options needed: /c
*/
#include <stdio.h>

#pragma data_seg (".SEG")

char szArray1 [] = "abc";
char *szPtr1 = NULL;

#pragma data_seg ()

char szArray2 [] = "123";
char *szPtr2 = NULL;

void func () {¬

    szPtr1 = szArray1;  // C2446 - pointer and array in named segment
    szPtr2 = szArray1;  // C2446 - array only in named segment
    szPtr1 = szArray2;  // no errors - array not in named segment
    szPtr2 = szArray2;  // no errors - array not in named segment
    szPtr1 = (char *)szArray1;  // no errors with type cast
}

Additional reference words: 1.00 8.00
KBCategory: Tls
KBSubcategory: CLIss

=============================================================================

Copyright Microsoft Corporation 1994.
