PRB: C4059 Incorrectly Generated by Casting Function to Void

ID Number: Q71889

6.00 6.00a 6.00ax | 6.00 6.00a

MS-DOS | OS/2

buglist6.00 buglist6.00a buglist6.00ax fixlist7.00

Summary:

SUMMARY

Microsoft C versions 6.0, 6.0a, and 6.0ax and QuickC versions 2.5

and 2.51 may incorrectly generate the following error when a

function is cast to type void:

warning C4059: segment lost in conversion

This warning appears only at warning level 2 (/W2) or higher in

compact (/AC), large (/AL), or huge (/AH) memory model. In C, the

problem occurs only when compiling with the quick compile (/qc)

option.

RESOLUTION

To work around this problem, compile with small (/AS) or medium

(/AM) memory model to avoid the typecast or do not use the /qc

option with Microsoft C.

STATUS

Microsoft has confirmed this to be a problem in C versions 6.0,

6.0a, and 6.0ax and QuickC versions 2.50 and 2.51 (buglist2.50 and

2.51). This problem was corrected in C version 7.0.

More Information:

The sample code below demonstrates this problem. The incorrect warning

is displayed when the strcpy() function is cast to void. By removing

the typecast in front of the strcpy() function, the warning will not

appear.

Sample Code

-----------

/* Compile options needed: /c /qc /W2 /AL

*/

#include <stdio.h>

#include <string.h>

void main(void)

{

char strl[80] = "not";

const char *str2 = "okay";

printf("%s\n", strl);

(void) strcpy(strl, str2);

printf("%s\n",strl);

}

Additional reference words: 2.50 6.00 6.00a 6.00ax