Pelles C forum

Pelles C => Bug reports => Topic started by: algernon_77 on November 27, 2026, 05:07:22 PM

Title: warning #2116 and SEH
Post by: algernon_77 on November 27, 2026, 05:07:22 PM
Not sure if a bug or a known issue/limitation.

Using __try/__except seems to confuse the compiler, see the example below (both x86 and x64). VARIANT 1 to 4 all crash, VARIANT 5 works. Using "S * volatile s" instead of "S * s" cures it in all cases - warning #2116 also goes away. Issue is not present in Pelles C 12.00.2. zipped project attached.


#include <windows.h>
#include <stdio.h>

#ifndef VARIANT
#define VARIANT 1
#endif

//#define NO_NULL_CHECK

typedef struct _S
{
    WPARAM      a;          /* 0x00 */
    LPARAM      b;          /* 0x08 */
    HWND        h;          /* 0x10 */
    HWND        p;          /* 0x18 */
    WCHAR       * x;        /* 0x20 */
    WCHAR       * y;        /* 0x28 */
    __int64     size;       /* 0x30 */
    __int64     * tbl;      /* 0x38 */
    UINT        err;        /* 0x40 */
    UINT_PTR    sub;        /* 0x48 */
    UINT_PTR    files;      /* 0x50 */
    UINT_PTR    depth;      /* 0x58 */
    UINT_PTR    index;      /* 0x60 */
} S;

static __int64 * g_tbl;

#if VARIANT == 4
BOOL Handler ( S * arg )
#elif VARIANT == 5
BOOL Handler ( S * s )
#else
BOOL Handler ( LPARAM arg )
#endif
{
#if VARIANT == 1                /* local, NULL init, then cast-assign     */
    S * s = NULL;
    s = (S *)arg;
#elif VARIANT == 2              /* local, no init, cast-assign (wfsize)   */
    S * s;
    s = (S *)arg;
#elif VARIANT == 3              /* local, cast in the initialiser         */
    S * s = (S *)arg;
#elif VARIANT == 4              /* local copy of a typed param, no cast   */
    S * s;
    s = arg;
#endif                          /* VARIANT 5: parameter used directly     */

#ifndef NO_NULL_CHECK
    if ( s != NULL )
#endif
    {
        g_tbl = s->tbl;

        __try
        {
            g_tbl[s->index] = s->size;
        }
        __except ( EXCEPTION_EXECUTE_HANDLER )
        {
            return FALSE;
        }

        if ( s->index % 256 == 0 )
        {
            printf ( "%zu %zu\n", s->sub, s->files );   /* faults here */
        }

        s->index++;
    }

    return TRUE;
}

int main ( void )
{
    __int64     tbl[16] = { 0 };
    S           s = { 0 };

    s.tbl   = tbl;
    s.size  = 1234;
    s.index = 0;

#if VARIANT >= 4
    printf ( "result: %d\n", Handler ( &s ) );
#else
    printf ( "result: %d\n", Handler ( (LPARAM)&s ) );
#endif

    return 0;
}