News:

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

Main Menu

Recent posts

#11
Bug reports / Re: Maybe a optimization bug.
Last post by Vortex - April 15, 2026, 10:35:59 AM
By the way, uncommenting the line below will output the correct result :

printf("i=%d\n",i);
#include <stdio.h>

int main(void)
{
    int i=1, sum=0;
    while (i<=100)
    {
        printf("i=%d\n",i);
        sum=sum+i;
        i++;
    }
    printf("i=%d\n",i);
    printf("sum=%d\n",sum);
    return 0;
}
#12
Bug reports / Re: Maybe a optimization bug.
Last post by TimoVJL - April 15, 2026, 07:55:56 AM
from Clang
main:
00000000  4883EC28                sub rsp, 28h
00000004  488D0D00000000          lea rcx, [??_C@_05BKKKKIID@i?$DN?$CFd?6?$AA@]
0000000B  BA65000000              mov edx, 65h
00000010  E800000000              call printf
00000015  488D0D00000000          lea rcx, [??_C@_07MJFEPNKA@sum?$DN?$CFd?6?$AA@]
0000001C  BABA130000              mov edx, 13BAh
00000021  E800000000              call printf
00000026  31C0                    xor eax, eax
00000028  4883C428                add rsp, 28h
0000002C  C3                      ret
As Vortex mentioned, this was missingmov edx, 65h
#13
Bug reports / Re: Maybe a optimization bug.
Last post by ander_cc - April 15, 2026, 05:09:23 AM
Quote from: John Z on April 14, 2026, 04:43:36 PMHi ander_cc,

A good lesson there similar to a lawyers credo "In Court don't ask a question if you don't already know the answer"  the corollary to teaching, esp programing, is "In classroom don't use an example you haven't tested"  :)  (half kidding you, no offense meant)

But seriously yes there have been, and are issues, with using the optimizations and extensive testing is always needed for these.  I have many programs using optimizations successfully.

Perhaps Pelle can find the cause of this short program, meanwhile

Your program can use optimizations by using this 'fix':

volatile int i=1;

which, as I understand it inhibits the optimizer from making assumptions about i.

John Z

As an aside I would recommend not using any optimizations for teaching.  Optimizing should be performed by the students learning programing.

Cheers,
Yes, It really embarrassed me at that time. I realized I had forgotten to turn off the optimization. Then I explained the reason to my students, and turned off optimization to test the code again, and used gcc -o2 to test the code again.
#14
General discussion / Re: Pelles C and Windows Defen...
Last post by MrBcx - April 15, 2026, 03:33:14 AM
Quote from: italofutura on April 14, 2026, 08:22:10 AMI do not have admin rights on this laptop.


I strongly suggest having a chat with someone in your IT dept.

Let them know that you want to do some work-related development but that you lack admin rights.

If they say "No", politely accept that they have their reasons for saying no.

Don't do anything that gives your employer cause to dismiss you.

#15
Bug reports / Re: Some fonts are missing fro...
Last post by TimoVJL - April 14, 2026, 09:13:09 PM
#16
Bug reports / Re: Maybe a optimization bug.
Last post by Vortex - April 14, 2026, 08:37:49 PM
Hi Timo,

Here is the output of Podump :

\PellesC\bin\podump.exe /DISASM output\sum.obj
sub               rsp,28
lea               rcx,[@152]
call              printf
lea               rcx,[@154]
mov               edx,13BA
call              printf
xor               eax,eax
add               rsp,28
ret
#17
Bug reports / Re: Some fonts are missing fro...
Last post by Vortex - April 14, 2026, 08:34:57 PM
Hi Timo,

Compiling your code, I get the font not found message on Windows 7 Sp1.
#18
Bug reports / Re: Maybe a optimization bug.
Last post by TimoVJL - April 14, 2026, 07:41:26 PM
For small tests quick look with podump.exe

Disasm obj Add-In
#19
Bug reports / Re: Some fonts are missing fro...
Last post by TimoVJL - April 14, 2026, 07:25:55 PM
Silly example to check if font exists
#define WIN32_LEAN_AND_MEAN
#include <windows.h>

int CALLBACK EnumFontFamProc(const LOGFONT *lpelf, const TEXTMETRIC *lpntm,
  DWORD FontType, LPARAM lParam)
{
    static int nCnt;
    OutputDebugString(lpelf->lfFaceName);
    if (!lstrcmp(lpelf->lfFaceName, (TCHAR*)lParam))
        nCnt++;
    return nCnt;
}

void __cdecl WinMainCRTStartup(void)
{
    HDC hDC = GetDC(GetDesktopWindow());
    //int nFont = EnumFontFamilies(hDC, TEXT("Consolas"), EnumFontFamProc, (LPARAM)TEXT("Consolas"));
    int nFont = EnumFontFamilies(hDC, TEXT("Cascadia Mono"), EnumFontFamProc, (LPARAM)TEXT("Cascadia Mono"));
    if (nFont) MessageBox(0, "font found", "Font", MB_OK);
    else MessageBox(0, "font not found", "Font", MB_OK);
    ExitProcess(0);
}
#20
Bug reports / Re: Maybe a optimization bug.
Last post by Vortex - April 14, 2026, 06:06:04 PM
Compiling the code with the maximize speed option :

#include <stdio.h>

int main(void)
{
    int i=1, sum=0;
    while (i<=100)
    {
        //printf("i=%d\n",i);
        sum=sum+i;
        i++;
    }
    printf("i=%d\n",i);
    printf("sum=%d\n",sum);
    return 0;
}

Disassembling the object module :

_text  SEGMENT PARA 'CODE'                            ; section number 1

main    PROC
        sub    rsp, 40                                ; 0000 _ 48: 83. EC, 28
        lea    rcx, [@152]                            ; 0004 _ 48: 8D. 0D, 00000000(rel)
        call    printf                                  ; 000B _ E8, 00000000(rel)
        lea    rcx, [@154]                            ; 0010 _ 48: 8D. 0D, 00000000(rel)
        mov    edx, 5050                              ; 0017 _ BA, 000013BA
        call    printf                                  ; 001C _ E8, 00000000(rel)
        xor    eax, eax                                ; 0021 _ 31. C0
        add    rsp, 40                                ; 0023 _ 48: 83. C4, 28
        ret                                            ; 0027 _ C3
main    ENDP

_text  ENDS

.xdata  SEGMENT ALIGN(8) 'CONST'                        ; section number 3

..?xdatasym1 label byte
        db 01H, 04H, 01H, 00H, 04H, 42H, 00H, 00H      ; 0000 _ .....B..

.xdata  ENDS

.rdata  SEGMENT PARA 'CONST'                            ; section number 4

@154    label byte
        db 73H, 75H, 6DH, 3DH, 25H, 64H, 0AH, 00H      ; 0000 _ sum=%d..

@152    label byte
        db 69H, 3DH, 25H, 64H, 0AH, 00H                ; 0008 _ i=%d..

.rdata  ENDS

The first printf call should take a second parameter, edx pointint the value of i. Since this statement is missing, printf will print the random value stored by the register edx.