News:

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

Main Menu

Recent posts

#21
Bug reports / Re: stdckdint.h bug report
Last post by TimoVJL - March 09, 2026, 12:10:59 PM
with dataset:
    int a = 655350;
    int b = 10;
    short c = 0;
Clang output:
true  c = -100
true  c = 0
true  c = -20
#22
Bug reports / Re: bug report. setvbuf() func...
Last post by TimoVJL - March 09, 2026, 11:54:49 AM
https://en.cppreference.com/w/c/io/setvbuf
buffer size should be at least multiple of 2
#23
Bug reports / Re: bug report. setvbuf() func...
Last post by ander_cc - March 09, 2026, 10:10:37 AM
Quote from: John Z on March 09, 2026, 09:56:30 AMHi ander,

I could not reproduce this.  With the setvbuf 1000, 5000, 7000, or not even use setvbuf it always ends the loop on 20000 .  I just pasted your code in. 
19998
19999
20000
Press any key to continue...

John Z
thank you for test.
I changed the number and try it again, and got different result, I got a new line "00".
Windows 11 Pro 25H2 simplified chinese. Only for chinese windows? I will try it on my laptop at home later

You cannot view this attachment.
#24
Bug reports / Re: bug report. setvbuf() func...
Last post by John Z - March 09, 2026, 09:56:30 AM
Hi ander,

I could not reproduce this.  With the setvbuf 1000, 5000, 7000, or not even use setvbuf it always ends the loop on 20000 .  I just pasted your code in. 
19998
19999
20000
Press any key to continue...

John Z
#25
Bug reports / bug report. setvbuf() function...
Last post by ander_cc - March 09, 2026, 07:53:45 AM
I have learned setvbuf() function last week. But got a strange error.
The setvbuf function last argument is buffer size. When I set 1000, 2000, 3000, 4000, will be OK, but when I set it to 5000 or 7000, I will get a additional line.
Then, I try the same code in gcc 15.2, it is correct.
#include <stdio.h>

int main(void)
{
setvbuf(stdout, NULL, _IOFBF, 7000);
for (int i = 0; i < 20001; i++)
printf("%d\n", i);

return 0;
}
You cannot view this attachment.
#26
Bug reports / Re: stdckdint.h bug report
Last post by ander_cc - March 09, 2026, 07:30:13 AM
Quote from: John Z on March 08, 2026, 09:26:14 PM👍👍👍

Definitely!  Thanks Timo.
Better output too -

    long int a = 65536;
    long int b = 65535;//10
    int c = 0;
---------output---------
result: true  c = -65536
result: false c = 131071
result: false c = 1
Press any key to continue...

John Z

Thank you for your reply, John Z.
The "long int" and the "int" are 32bit value in Pelles c.
I get the false when only the first argument overflow in function ckd_add, I think it is a bug.
#include <stdio.h>
#include <stdckdint.h>
int main(void)
{
int a = 655350;
int b = 10;
short int c = 0;

bool result = true;
result = ckd_add(&c, a, b); //out of range of short. a and b are int, c is short int.
if (result == true)
{
puts("true");
}else{
puts("false");
}
printf("c = %d ", c);

return 0;
}
#27
Bug reports / Re: stdckdint.h bug report
Last post by ander_cc - March 09, 2026, 07:23:31 AM
Quote from: TimoVJL on March 08, 2026, 03:10:42 PMhttps://cppreference.net/c/numeric/ckd_mul.html
thank you for your reply,  TimoVJL. I have read it. please try my test code.
Pelles C 13.01 will print :
false
c = 0
but gcc 15.2 will print :
true
c = 0

And I read the Pelles C help file for "stdckdint.h". I think the return value depends on first argument type. But Pelles C returns false when the first argument overflow in following code.
#include <stdio.h>
#include <stdckdint.h>
int main(void)
{
int a = 655350;
int b = 10;
short int c = 0;

bool result = true;
result = ckd_add(&c, a, b); //out of range of short. a and b are int, c is short int.
if (result == true)
{
puts("true");
}else{
puts("false");
}
printf("c = %d ", c);

return 0;
}
#28
Bug reports / Re: stdckdint.h bug report
Last post by John Z - March 08, 2026, 09:26:14 PM
👍👍👍

Definitely!  Thanks Timo.
Better output too -

    long int a = 65536;
    long int b = 65535;//10
    int c = 0;
---------output---------
result: true  c = -65536
result: false c = 131071
result: false c = 1
Press any key to continue...

John Z
#29
Bug reports / Re: stdckdint.h bug report
Last post by TimoVJL - March 08, 2026, 03:10:42 PM
https://cppreference.net/c/numeric/ckd_mul.html

Just easier to read:
#include <stdio.h>
#include <stdckdint.h>
char *ab[] = {"false", "true "};
int main(void)
{
    long int a = 655350;
    long int b = 655350;//10
    int c = 0;
    bool result;
    result = ckd_mul(&c, a, b); // ckd_add(&c, a, b); ckd_sub(&c, a, b);
    printf("result: %s c = %d\n", ab[result], c);

    result =  ckd_add(&c, a, b); // ckd_sub(&c, a, b);
    printf("result: %s c = %d\n", ab[result], c);

    result = ckd_sub(&c, a, b);
    printf("result: %s c = %d\n", ab[result], c);
    return 0;
}
#30
Bug reports / Re: stdckdint.h bug report
Last post by John Z - March 08, 2026, 10:13:46 AM
Hi Ander,

Well not always - If the numbers are big enough to 'wrap' you'll get 'true'
for example - output from code below :
true
c = -13107100
false
c = 1310700
false
c = 0
Press any key to continue...
#include <stdio.h>
#include <stdckdint.h>
int main(void)
{
    long int a = 655350;
    long int b = 655350;//10
    int c = 0;
    //int c = 0;
    bool result = true;
    result = ckd_mul(&c, a, b); // ckd_add(&c, a, b); ckd_sub(&c, a, b);
    if (result == true) {
        puts("true\n");
    }else{
        puts("false\n");
    }
    printf("c = %d\n", c);   
    result =  ckd_add(&c, a, b); // ckd_sub(&c, a, b);
    if (result == true) {
        puts("true\n");
    }else{
        puts("false\n");
    }
    printf("c = %d\n", c);
    result = ckd_sub(&c, a, b);
    if (result == true) {
        puts("true\n");
    }else{
        puts("false\n");
    }
    printf("c = %d\n", c);
    return 0;
}

Cheers,
John Z