Page 1 of 1

Undefined behavior - C backend

Posted: Tue Feb 10, 2026 7:28 pm
by ricardo_sdl
Hi!
How does PureBasic C Backend compiler handles undefined behavior on the C generated code?
This PureBasic code:

Code: Select all

EnableExplicit

OpenConsole()

Define i.i = $7FFFFFFFFFFFFFFF

PrintN(Str(i))

i + 1

PrintN(Str(i))

Input()
Generated this C code in my test:

Code: Select all

// Define i.i = $7FFFFFFFFFFFFFFF
v_i=9223372036854775807;
// 
// PrintN(Str(i))
SYS_PushStringBasePosition();
SYS_PushStringBasePosition();
SYS_PushStringBasePosition();
PB_Str(v_i,SYS_PopStringBasePosition());
void* p0=(void*)SYS_PopStringBasePositionValueNoUpdate();
integer rr1=PB_PrintN(p0);
SYS_PopStringBasePositionUpdate();
// 
// i + 1
v_i=(v_i+1);
// 
// PrintN(Str(i))
Both backends (asm and c) executed and resulted in the same output:
9223372036854775807
-9223372036854775808
But depending on the C compiler used and compilation flags the result can be different. So how is it handled or is it we should look out for?