open-watcom / open-watcom-v2

Open Watcom V2.0 - Source code repository, Wiki, Latest Binary build, Archived builds including all installers for download.
Other
991 stars 163 forks source link

Pointer mismatch error and too big structs and buffers #1293

Closed headscott closed 6 months ago

headscott commented 6 months ago

I compiled a c-file with wcc, but it says

Error! E1176: Parameter 1, pointer type mismatch
Note! N2003: source conversion type is 'unsigned char *'
Note! N2004: target conversion type is 'struct MyHash *'

If I compile the exact same file with gcc and these options: -w -ffreestanding -c there is no error reported, it's just a warning (I can see it, if I remove -w option).

Is there a way, that wcc also treat this "error" as a warning?

Edit: There is another error appearing:

Error! Error E1020: Dimension cannot be 0 or negative

the line code looks like this:

uint8_t code_buf[CODE_BUF_SIZE]

and CODE_BUF_SIZE is defined in an enum:

enum { CODE_BUF_SIZE = 24*1024, ....};

so it is > 0

jmalak commented 6 months ago

A bug is a bug and should be fixed instead of masked. We don't want to implement such gcc feature for lazy programmers. A portable solution according to the C standard is to cast types (if you want to do such a dangerous thing) or use "void *" or union. If you are doing such dangerous things, it is your business to handle them properly. Do not ask to change the compiler.

headscott commented 6 months ago

Okay, I will change them then in my code. I just hoped there is already something possible to do that.

But according to the other error message:

If I compile this file:

#define SIZE 64*1024
int buf[SIZE];

This error appears: Error! Error E1020: Dimension cannot be 0 or negative

Even if I do

int buf[65536];

It gives me the error:

Error! Error E1157: Variable must be 'huge'

Is it also a bug in my code or does wcc have other limitations here? Can I do that without errors?

headscott commented 6 months ago

I just need to declare the array as '__huge' right?

int __huge buf[65536];

But then wcc says

Error! E1098: Maximum struct or union size is 64K

And what about the define? I would not want to set all used positions by hand if I change the size again

jmalak commented 6 months ago

you can use macro for array size as usual. What you mean by define exactly, it is regular array? Only address calculation is done as for huge object that it is always normalize to segm:>offset( 0-0x0F)

headscott commented 6 months ago

I mean I want to be able to do

#define SIZE 65536

as well as

#define SIZE 64*1024

and my struct which contains an array of SIZE unsigned char elements, but also other variables, got too big. See that error:

Error! E1098: Maximum struct or union size is 64K

and I cannot declare my struct as '__huge'

jmalak commented 6 months ago

I don't understand why you have a problem. below is sample code using __huge object which compile OK.

define MAX 65537

int __huge a[MAX];

int __huge *test( int i )
{
    return( &a[i] );
}

and dissasembled code

                PUBLIC  test_
                PUBLIC  _a
                EXTRN   __PIA:BYTE
                EXTRN   _small_code_:BYTE
DGROUP          GROUP   CONST,CONST2,_DATA
_TEXT           SEGMENT BYTE PUBLIC USE16 'CODE'
                ASSUME CS:_TEXT, DS:DGROUP, SS:DGROUP
test_:
        push            bx
        push            cx
        push            si
        cwd
        mov             si,ax
        mov             cx,dx
        shl             si,1
        rcl             cx,1
        mov             ax,offset _a
        mov             dx,seg _a
        mov             bx,si
        call            near ptr __PIA
        pop             si
        pop             cx
        pop             bx
        ret
_TEXT           ENDS
CONST           SEGMENT WORD PUBLIC USE16 'DATA'
CONST           ENDS
CONST2          SEGMENT WORD PUBLIC USE16 'DATA'
CONST2          ENDS
_DATA           SEGMENT WORD PUBLIC USE16 'DATA'
_DATA           ENDS
huge13_DATA             SEGMENT PARA PRIVATE USE16 'FAR_DATA'
_a:
    DB  1fffH DUP(0,0,0,0,0,0,0,0)
    DB  0, 0, 0, 0, 0, 0, 0, 0

huge13_DATA             ENDS
huge14_DATA             SEGMENT PARA PRIVATE USE16 'FAR_DATA'
    DB  1fffH DUP(0,0,0,0,0,0,0,0)
    DB  0, 0, 0, 0, 0, 0, 0, 0

huge14_DATA             ENDS
huge15_DATA             SEGMENT PARA PRIVATE USE16 'FAR_DATA'
    DB  0, 0

huge15_DATA             ENDS
                END

__PIA is special "huge" pointer aritmetic function to add index and create output normalized pointer.

headscott commented 6 months ago

I also use a struct where I did something like this:

#define MAX 64*1024 //first problem here, need to define to 65536 by hand (why?/how can I do it with 64*1024 anyways?)
typedef struct
{
  int element;
  int __huge buffer[MAX]; //this one exceeds 64K which seems to be the max size of structs
} __huge elementname;

and get this error:

Error! E1098: Maximum struct or union size is 64K

jmalak commented 6 months ago

It is clear what you do wrong, single huge object cannot be > 65536 bytes. You cannot add huge array to structure. It is bad design. You can use huge array of structures where size of struct < 65536 bytes.

headscott commented 6 months ago

Wait... can I fix this by using wcc386 instead of wcc?

jmalak commented 6 months ago

wcc is for 16-bit architecture (segmented 64kBytes) but wcc386 for 32-bit architecture I suppose that you know it.

headscott commented 6 months ago

Yeah true... thank you anyways. I would need to rearrange my files a bit