News:

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

Main Menu

Recent posts

#31
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
#32
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
#33
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.
#34
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.
#35
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;
}
#36
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?
#37
Tips & tricks / Re: Implementation of CommandL...
Last post by TimoVJL - May 22, 2026, 01:52:06 PM
Nice to have, if want to have a common ANSI / UNICODE project.
#38
Tips & tricks / Implementation of CommandLineT...
Last post by Vortex - May 21, 2026, 10:13:13 PM
QuoteImplementation of CommandLineToArgv for Win32
(ANSI and alternative Unicode versions)

http://alter.org.ua/docs/win/args/

QuoteCommandLineToArgvA

Collection of functions implement CommandLineToArgvA, the ANSI version of CommandLineToArgvW in windows API

https://github.com/futurist/CommandLineToArgvA
#39
Beginner questions / Re: same code pelles c and gcc...
Last post by John Z - May 21, 2026, 03:13:02 AM
Quote from: ander_cc on March 15, 2026, 11:30:22 AM#include <stdio.h>
#include <stdbit.h>
int main() {
    unsigned short a1 = 4;
    unsigned int a2 = 4;

    printf("a1 one:%u  a1 zero:%u\n", stdc_first_leading_one(a1), stdc_first_leading_zero(a1));
    printf("a2 one:%u  a2 zero:%u\n", stdc_first_leading_one(a2), stdc_first_leading_zero(a2));
   
    return 0;
}
gcc 11.4 -std=c23
a1 one:14  a1 zero:1
a2 one:30  a2 zero:1
-----
pelles c 13.01
a1 one:3  a1 zero:16
a2 one:3  a2 zero:32
-----
WHY? and which is right?

Confirming Pelles C 14.1 now reports
a1 one:14  a1 zero:1
a2 one:30  a2 zero:1


John Z
#40
Assembly discussions / Re: Combining object files
Last post by Vortex - May 16, 2026, 10:07:19 PM
Hi Timo,

Thanks, it's all about practical programming. Right tool for the right job.