BUG: C4306 Warning when Using Signal Handler

ID: Q119224

7.00 | 1.00 1.50 MS-DOS | WINDOWS kbtool kbbuglist

The information in this article applies to:

SYMPTOMS

When using the signal function in the medium-, large-, or huge-memory models of C/C++ version 7.0, 8.0, or 8.0c, it is possible to get the following warning message when warning level 4 (/W4) is used:

In C/C++ versions 8.0 and 8.0c, the warning appears as:

   warning C4306: 'cast' : conversion from 'const int ' to 'void (__far
                  __cdecl *)(int )' of greater size

In C/C++ version 7.0, the warning appears as:

   warning C4306: conversion of integral type to pointer of greater
                  size

This is a minor warning and can safely be ignored.

CAUSE

This warning occurs because of incorrect definitions of SIG_DFL, SIG_IGN, and SIG_ERR in the SIGNAL.H header file. These definitions are function pointers that are being assigned integer values. Far function calls require four bytes rather than the two bytes that an integer uses.

RESOLUTION

This warning message can be fixed by changing the definitions of SIG_DFL, SIG_IGN, and SIG_ERR in the SIGNAL.H file as follows:

   /* if small or compact model */ 
   #if ((defined (_M_I86SM)) || (defined (_M_I86CM)))

   #define SIG_DFL (void (__cdecl *)(int))0
   #define SIG_IGN (void (__cdecl *)(int))1
   #define SIG_ERR (void (__cdecl *)(int))-1

   /* other models */ 
   #else

   #define SIG_DFL (void (__cdecl *)(int))0L
   #define SIG_IGN (void (__cdecl *)(int))1L
   #define SIG_ERR (void (__cdecl *)(int))-1L

   #endif

Instead of changing the SIGNAL.H file, however, you can use a pragma to disable the warning as follows:

   #pragma warning (disable:4306)

MORE INFORMATION

This problem can be reproduced using the SIGNAL.C sample that is available in the "Run-Time Library Reference" or in the online Help for C/C++ version 7.0 or Visual C/C++ versions 1.0 and 1.5.

Additional reference words: 7.00 1.00 1.50 KBCategory: kbtool kbbuglist KBSubcategory: CLIss Keywords : kb16bitonly

Last Reviewed: July 23, 1997