News:

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

Main Menu

Recent posts

#71
Assembly discussions / Re: Combining object files
Last post by Pelle - June 18, 2026, 08:37:54 PM
OK. I still don't see the point in having a tool that combines object files, but never mind. Not important.
#72
Assembly discussions / Re: Variadic functions
Last post by Vortex - June 14, 2026, 09:46:07 PM
Simple printf emulator using only the bare percentage symbol to represent strings :

.386
.model flat,stdcall
option casemap:none

includelib \PellesC\lib\Win\kernel32.lib
includelib \PellesC\lib\Win\user32.lib

ExitProcess PROTO :DWORD

printfX PROTO C format:DWORD,args:VARARG

.data

format1 db 'This is a % % to % %',0
str1    db 'printfX',0
str2    db 'demo',0
str3    db 'type',0
str4    db 'strings.',0

.code

start:

    invoke   printfX,ADDR format1,
             ADDR str1,ADDR str2,
             ADDR str3,ADDR str4
             
    invoke   ExitProcess,0

END start
#73
Assembly discussions / Re: Combining object files
Last post by Vortex - June 14, 2026, 09:43:31 PM
Hi Pelle,

The purpose of merging object modules is to provide only one monolytic object file to the linker. Nothing fancy. As you said, it's preferable to create a static library.
#74
Assembly discussions / Re: Combining object files
Last post by Pelle - June 14, 2026, 09:31:20 PM
but... when is this useful??

I can only think of two things to do with an object file:
1) pass it to the linker
2) put in in a library/archive, and pass that to the linker

I mean, normally you have the source code, and anything of importance that needs to change in the object file is better handled by editing the source code and rebuild.
If you don't have the source code, well... disregarding any legal issues, if you don't known exactly what you are doing, random changes will probably cause more harm than good (and don't expect tools at this level to warn you much).
#75
Bug reports / Re: Segmentation fault with se...
Last post by Pelle - June 14, 2026, 09:17:16 PM
As suggested by TimoVJL,
replacing
malloc(...)with
aligned_alloc(16, ...)works for me...
#76
Bug reports / Re: Calling cc with CreateProc...
Last post by Pelle - June 14, 2026, 09:13:32 PM
Thomas, I have already spent a fair amount of time investigating this problem. I'm still looking for a proper solution. This is going to take some time...
#77
Add-ins / Batch Builder
Last post by John Z - June 14, 2026, 02:49:41 AM
Add-In BBBBuilderPS.dll version 1.0  06/09/2026

The BBBBuilder.dll will create either a .bat file that when run from the command line will build the program that was open at the time BBBBuilder was invoked or a PowerShell .ps1 file which will do the same.

Essentially BBBBuilderPS creates a .bat or .ps1 file to perform a build similar to what cc does, but maybe easier . . .

Once built the batch file can be run at any time without using the IDE.
Source files can be added, removed or modified in the file lists, and then rebuild the program using the batch file.

It is a menu item BBBBuilder PS, under Project, below Workspace, and it is also a button on the toolbar (hammer & nail) :)

More information in the readme.txt file included with the sources -

John Z

Big Beautiful Batch Builder - one more B than Pres. Trump used  ;D  ;D  ;D

Note: This add-in is unrelated to the recently discovered cc issue, and was started long before it.
#78
Bug reports / Re: Segmentation fault with se...
Last post by MrBcx - May 30, 2026, 04:56:04 PM
Another observation:

If compiled to 32-bit:

In main
malloc successful
okay


If compiled to 64-bit:

In main
malloc successful
unhandled exception
#79
Bug reports / Re: Segmentation fault with se...
Last post by TimoVJL - May 30, 2026, 09:24:28 AM
An alignment error at memory for jmp_buf at x64

Simple test:
catch_type *pcs;
...
  catch_stack = (catch_type *)(malloc(max_catch_stack * sizeof(catch_type)+8));
  pcs = (catch_type *)(((long long)catch_stack) + ((long long)catch_stack % 16));
  printf("%p %p\n", catch_stack, pcs);
...
if ((fail_value = do_setjmp(pcs[catch_stack_pos])) == 0) {

Dynamic jmp_buf should allocated using aligned_alloc() function for x64.

Quote7.24.3 Memory management functions
1 The order and contiguity of storage allocated by successive calls to the aligned_alloc, calloc,
malloc, and realloc functions is unspecified. The pointer returned if the allocation succeeds is
suitably aligned so that it may be assigned to a pointer to any type of object with a fundamental
alignment requirement and size less than or equal to the size requested. It may then be used to
access such an object or an array of such objects in the space allocated (until the space is explicitly
deallocated).
#80
Bug reports / Segmentation fault with setjmp...
Last post by Thomas Mertes - May 30, 2026, 07:46:21 AM
If I compile and run the program below with gcc it writes:

In main
malloc successful
okay

Other C compilers have also no problem with this test program.
If I compile and run this test program with Pelles C it
triggers a segmentation fault after writing:

In main
malloc successful

This is the test program:

#include <stdio.h>
#include <stdlib.h>
#include <setjmp.h>

#define do_setjmp(jump_buf) setjmp(jump_buf)
typedef jmp_buf catch_type;
catch_type *catch_stack;
size_t catch_stack_pos;
size_t max_catch_stack;

int main (int argc, char **argv)
{
  int fail_value;
  catch_stack_pos = 0;
  max_catch_stack = 128;
  printf("In main\n");
  fflush(stdout);
  catch_stack = (catch_type *)(malloc(max_catch_stack * sizeof(catch_type)));
  if (catch_stack != NULL) {
    printf("malloc successful\n");
    fflush(stdout);
    if ((fail_value = do_setjmp(catch_stack[catch_stack_pos])) == 0) {
      printf("okay\n");
      fflush(stdout);
    }
  }
  return 0;
}