News:

Download Pelles C here: http://www.smorgasbordet.com/pellesc/

Main Menu

Recent posts

#51
Expert questions / Re: Struggling with function p...
Last post by Pelle - June 02, 2025, 09:29:39 AM
Quote from: Akko on June 01, 2025, 09:34:04 PMGosh, I must have been blinded by our recent thunderstorm...
... but of course ... the famous thunderstorm excuse...  ;D
#52
Expert questions / Re: Using a structure as retur...
Last post by Pelle - June 02, 2025, 09:26:26 AM
Just to be clear: redeclaring a typedef in C99 mode, and not using Microsoft mode (/Ze), will fail.
But this is not relevant in this case...
#53
Expert questions / Re: Re: Using a structure as r...
Last post by pkparchure - June 02, 2025, 08:06:12 AM
As suggested by TimoVJL, I put typedef Statistics Statistics; in file gsStat.c as given below:

typedef Statistics Statistics;

// Function to calculate all statistics
Statistics calculate_statistics(DataStruct gsData, int nRows, int vCol)
{

And it works, the functions {} calculate_statistics is now visible in the panel. Also, the program compiles and runs very well.

It also works if I put: typedef Statistics Statistics; in header file gs.h

Once again, thank you very much Pelle, John Z, TimoVJL, and Mr BCX for the help and guidance.





#54
Expert questions / Re: Re: Using a structure as r...
Last post by John Z - June 01, 2025, 10:19:11 PM
Good explanation Pelle.

Also explains why it always worked for me - everything in the same file for my tests ...

John Z
#55
Expert questions / Re: Using a structure as retur...
Last post by TimoVJL - June 01, 2025, 10:03:38 PM
So, after addingtypedef Statistics Statistics;to gsStat.c, project panel shows {} calculate_statistics
#56
Expert questions / Re: Struggling with function p...
Last post by Akko - June 01, 2025, 09:34:04 PM
Gosh, I must have been blinded by our recent thunderstorm...
Thank you!   :)  :)  :)
#57
Expert questions / Re: Struggling with function p...
Last post by Pelle - June 01, 2025, 08:34:24 PM
OK, the quick & dirty version (with minimum changes):

#include <stdlib.h>

int pop(void) { return rand()&3; }
int tos=0x123456;

typedef int (*PZ)();
typedef int (*PN)(int, ...);

PZ pz;
PN pn;

void runproc(void) { // RUNPROC ( .. fa n -- ret )
   int p1, p2;
   switch (pop()) {
   case 0:   pz=(PZ)tos;
      tos=pz();
      break;
   case 1:   pn=(PN)pop(), p1=tos;
      tos=pn(p1);
      break;
   case 2:   pn=(PN)pop(), p2=pop(), p1=tos;
      tos=pn(p1,p2);
      break;
   default: tos=-21; }
}

int main(void) {
   runproc();
   return tos;
}
#58
Expert questions / Struggling with function point...
Last post by Akko - June 01, 2025, 07:54:21 PM
Hi,
I'm not sure if I'm struggling with my limited knowledge of function pointer syntax or with Pelles C.

The code snippet below (don't ask what it does) compiles flawlessly with gcc, but not with Pelles C V13
(32 bit console mode).

With Pelles C I get the following errors
E:\Develop\M3\fp.c(12): error #2168: Operands of '=' have incompatible types: 'int (*)()' and 'void *'.
E:\Develop\M3\fp.c(15): error #2168: Operands of '=' have incompatible types: 'int (*)(int, ...)' and 'void *'.
E:\Develop\M3\fp.c(18): error #2168: Operands of '=' have incompatible types: 'int (*)(int, ...)' and 'void *'.

I tried many things, including typedefs, without success. But I can't make it work.

Many thanks for your help!!

// ------
#include <stdlib.h>

int pop(void) { return rand()&3; }
int tos=0x123456;

int (*pz)();
int (*pn)(int,...);

void runproc(void) { // RUNPROC ( .. fa n -- ret )
   int p1, p2;
   switch (pop()) {
   case 0:   pz=(void*)tos;
      tos=pz();
      break;
   case 1:   pn=(void*)pop(), p1=tos;
      tos=pn(p1);
      break;
   case 2:   pn=(void*)pop(), p2=pop(), p1=tos;
      tos=pn(p1,p2);
      break;
   default: tos=-21; }
}

int main(void) {
   runproc();
   return tos;
}
// ------
#59
Expert questions / Re: Using a structure as retur...
Last post by Pelle - June 01, 2025, 03:55:29 PM
Parsing the C language is hard. There is some agreement it's one of the harder ones.
( Without more context: does "X * Y" means variable X times variable Y, or is Y a pointer to typedef X? And so on. )

rypedef names are one complication. There are "forks" in the syntax where the parser must know if a name is a type or a variable, to correctly parse the code that follows.

The Pelles C tool that collects information about types are variables is POBR.DLL (with a command-line interface in POBR.EXE). Since POBR.DLL is also used by the IDE, it needs to "work" in interactive mode and on a project that is probably unfinished. Because of this it's generally no time (nor point) to scan every #include file (of every #include file). There may be time to search the symbol database for any recorded typedef names, but doing this repeatedly on an older/slower computer may not br a huge success either.

All that said, what you have is a typedef name in one file (gs.h) used in another file (gsStat.c) and the problem is connecting the two pieces. The current version of POBR.DLL can't hande this well. For now there are only a few options:
1) add a tag to the "Statistics" struct so you can replace the return type "Statistics" with struct <tagname>,
2) make use of one of the heuristics in POBR.DLL to identify a typedef name: <lowercase>_t (generic) or <UPPERCASE> (windows mode), and rename your structs accordingly, or
3) wait for the future, where a new version of POBR.DLL *may* appear that *may* fix this (or not - I can't really see into the future).
#60
Assembly discussions / Syslink demo
Last post by Vortex - June 01, 2025, 12:41:01 PM
Hello,

Here is a syslink control demo :

WndProc PROC hWnd:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD
           
    .IF uMsg==WM_DESTROY

        invoke  PostQuitMessage,NULL

    .ELSEIF uMsg==WM_CREATE

        invoke  CreateWindowEx,0,ADDR SysClass,ADDR text,\
                WS_CHILD or WS_VISIBLE or WS_CLIPSIBLINGS or WS_CLIPCHILDREN,\
                20,20,200,40,hWnd,9999,hInstance,0

        mov     hSyslink,eax
        invoke  GetDlgCtrlID,eax
        mov     SyslinkID,eax

    .ELSEIF uMsg==WM_NOTIFY

        mov eax,SyslinkID
       
            .IF wParam==eax
           
                mov edx,lParam
               
                .IF NMHDR.code[edx]==NM_CLICK || NMHDR.code[edx]==NM_RETURN
                    invoke ShellExecute,0,ADDR verb,ADDR url,NULL,NULL,SW_SHOWNORMAL
                .ENDIF
               
            .ENDIF