News:

Download Pelles C here: http://www.pellesc.se

Main Menu

Recent posts

#71
Bug reports / Re: Calling cc with CreateProc...
Last post by Michele - May 28, 2026, 06:42:47 PM
The following sample works for me:
int wmain(int argc, wchar_t *wargv[])
{
    // 1. Define the command line in a mutable buffer
    wchar_t application[] = L"\\\\?\\c:\\Program Files\\PellesC\\Bin\\cc.exe";
    wchar_t commandLine[] = L"/help";

    // 2. Initialize the structures
    STARTUPINFOW si;
    PROCESS_INFORMATION pi;

    // Zero out the memory for both structures
    SecureZeroMemory(&si, sizeof(si));
    si.cb = sizeof(si);
    SecureZeroMemory(&pi, sizeof(pi));

    wprintf(L"Launching PellesC cc compiler driver using CreateProcessW...\n");

    // 3. Call CreateProcessW
    BOOL success = CreateProcessW
    (
        application,    // Application name
        commandLine,    // Command line arguments (must be mutable)
        NULL,          // Process handle not inheritable
        NULL,          // Thread handle not inheritable
        FALSE,          // Set handle inheritance to FALSE
        0,              // No creation flags
        NULL,          // Use parent's environment block
        NULL,          // Use parent's starting directory
        &si,            // Pointer to STARTUPINFOW structure
        &pi            // Pointer to PROCESS_INFORMATION structure
    );

    // 4. Check for success
    if (!success)
    {
        wprintf(L"CreateProcessW failed. Error code: %lu\n", GetLastError());
        return 1;
    }

    wprintf(L"Process started successfully!\n");
    wprintf(L"Process ID (PID): %lu\n", pi.dwProcessId);

    // 5. Clean up handles to avoid leaks
    CloseHandle(pi.hProcess);
    CloseHandle(pi.hThread);

    return 0;
}

Maybe you use a literal string for the command line string? MS documentation (See here) requires a modifiable memory for it:
QuoteThe Unicode version of this function, CreateProcessW, can modify the contents of this string. Therefore, this parameter cannot be a pointer to read-only memory (such as a const variable or a literal string). If this parameter is a constant string, the function may cause an access violation.
Maybe other compiler create a buffer automagically for CommandLine?
#72
Bug reports / Calling cc with CreateProcessW...
Last post by Thomas Mertes - May 28, 2026, 01:40:40 PM
if I start PellesC from the command line with

cc -Go chkccomp.c

it works, but if I use

CreateProcessW("\\?\c:\Program Files\PellesC\Bin\cc.exe", ""c:\Program Files\PellesC\Bin\cc.exe" -Go chkccomp.c", ...)

it fails with: can't open input file 'Files\PellesC\Bin\pocc.exe'.

So it obviously has problems with the space in the commandLine path.

BTW.: The quotes around the commandLine parameter of CreateProcessW() are from the log statement. The actual commandLine parameter is:

"c:\Program Files\PellesC\Bin\cc.exe" -Go chkccomp.c

Calling other programs (gcc, clang, etc.) with CreateProcessW() does not trigger such problems.

It seems that the parsing of the commandLine is not done correctly by cc.exe.

If I use

CreateProcessW("\\?\c:\Program Files\PellesC\Bin\cc.exe", "cc.exe -Go chkccomp.c", ...)

It works. But my code to start processes is generic and other programs need the full path in the commandLine parameter. I am really not able to code around this weakness of cc.exe without hurting other things.

Please fix the commandLine parsing of cc.exe to allow a quoted path with spaces.
#73
Assembly discussions / Re: Variadic functions
Last post by TimoVJL - May 27, 2026, 10:49:11 AM
Interesting code
Same with C
#include <stdio.h>
#include <stdarg.h>

int VaFunc(int, ...);

char f[] = "Sum = %u\n";

int __cdecl main(void)
{
    printf(f, VaFunc(3,5,6,7));
    return 0;
}

int VaFunc(int n, ...)
{
    int sum = 0;
    va_list args;
    va_start(args, n);
    for (int i = 0; i < n; i++)
        sum += va_arg(args, int);
    va_end(args);
    return sum;
}
#74
Assembly discussions / Re: Variadic functions
Last post by Vortex - May 26, 2026, 12:32:38 PM
Here is another version :

.386
.model flat,stdcall
option casemap:none

ExitProcess PROTO :DWORD
printf PROTO C :DWORD,:VARARG
VaFunc PROTO C :DWORD,:VARARG

.data

f db 'Sum = %u',0

.code

start:

    invoke  VaFunc,3,5,6,7

    invoke  printf,ADDR f,eax

    invoke  ExitProcess,0

OPTION PROLOGUE:NONE
OPTION EPILOGUE:NONE

VaFunc PROC C x:DWORD,y:VARARG

    xor     eax,eax
    mov     edx,DWORD PTR [esp+4]
@@:
    add     eax,DWORD PTR [esp+4*edx+4]
    dec     edx
    jnz     @b
    retn

VaFunc ENDP
   
OPTION PROLOGUE:PrologueDef
OPTION EPILOGUE:EpilogueDef

END start
#75
Assembly discussions / Variadic functions
Last post by Vortex - May 25, 2026, 12:46:11 PM
Here is a variadic function example, the VaFunc function calculates the sum of DWORDs.

.386
.model flat,stdcall
option casemap:none

ExitProcess PROTO :DWORD
printf PROTO C :DWORD,:VARARG
VaFunc PROTO C :DWORD,:VARARG

.data

f db 'Sum = %u',0

.data?

retaddr dd ?
i       dd ?

.code

start:

    push    7
    push    6
    push    5
    push    3
    call    VaFunc

    invoke  printf,ADDR f,eax

    invoke  ExitProcess,0

OPTION PROLOGUE:NONE
OPTION EPILOGUE:NONE

VaFunc PROC C x:DWORD,y:VARARG

    pop     retaddr
    pop     edx
    xor     eax,eax
@@:
    pop     ecx
    add     eax,ecx
    inc     i
    cmp     edx,i
    jne     @b
   
    push    retaddr
    retn

VaFunc ENDP
   
OPTION PROLOGUE:PrologueDef
OPTION EPILOGUE:EpilogueDef

END start
#76
Bug reports / Re: array struct assignments
Last post by John Z - May 25, 2026, 07:56:59 AM
Don't sweat it  :) many of us end up there every once in a while....


John Z
#77
Bug reports / Re: array struct assignments
Last post by PaoloC13 - May 25, 2026, 12:00:54 AM
Regret. I have to go back to the beginners forum.
#78
Bug reports / Re: array struct assignments
Last post by Michele - May 24, 2026, 05:44:45 PM
You should never return an automatic variable.
's' is allocated on the stack, and is overwritten by other data when function exits.
You can declare it 'static' as suggested or define it in the caller and pass it.
#79
Bug reports / Re: array struct assignments
Last post by TimoVJL - May 24, 2026, 05:08:29 PM
Think using static keyword
Mat4 broken(void) {
    static Mat4 s;
    memset(&s, 0, sizeof(s));   // set the block
    s.m[0] = 1.0f;              // explicit
    return s;
}
#80
Bug reports / array struct assignments
Last post by PaoloC13 - May 24, 2026, 04:24:16 PM
When I copy a returned struct { T arr[N]; } into the caller, it skips array elements whose value came from memset or ={0}. Only elements with explicit individual assignments are written.

typedef struct { float m[16]; } Mat4;

    Mat4 broken(void) {
        Mat4 s;
        memset(&s, 0, sizeof(s));   // set the block
        s.m[0] = 1.0f;              // explicit
        return s;
    }

    // Caller:
    Mat4 result;
    memset(&result, 0xCC, sizeof(result));   // fill with known garbage
    result = broken();

  /* Expected per C standard: result.m[1] == 0.0f           */
  /* Observed:                result.m[1] == -1.07374e+08   */
  /*   (the 0xCC garbage — the copy never wrote that slot)  */

Test: pre-fill the destination with a recognisable non-zero sentinel (0xCC bytes works well) before the call.
If any zero-expected field shows the sentinel value after the call, the copy skipped it.

My fix: explicitly assign every element of the array.
Is this a bug or a normal behaviour?