Page 2 of 2 FirstFirst 12
Results 11 to 17 of 17

Thread: [C related] Structs, records, pointers...

  1. #11

    [C related] Structs, records, pointers...

    Uhm... I don't know... sizeof gives 60 for c struct and 56 for pascal record :think:
    Get your fpc4gba copy now!
    Get your fpc4nds copy now!

  2. #12

    [C related] Structs, records, pointers...

    sizeof the unpacked record in delphi is 60. What exactly is a vuintxx?

    edit: a quick search tells me it means a volatile field? how could the end of a c struct be volatile?
    Peregrinus, expectavi pedes meos in cymbalis
    Nullus norvegicorum sole urinat

  3. #13

    [C related] Structs, records, pointers...

    Really I don't care about volatile, because it is an optimization that fpc can't handle yet, so I simply ignore it.

    Correction: the record size is 60 too... I forgot to remove a "packed" I have put to make a try ops:

    BTW, the alignment problem remains
    Get your fpc4gba copy now!
    Get your fpc4nds copy now!

  4. #14

    [C related] Structs, records, pointers...

    If you find out where in the struct the alignment differs then
    you could make a packed record, and then inserting padding
    bytes manually until it fits.

    Like this:

    [pascal]sTransferRegion = packed record
    heartbeat: cuint32;
    touchX, touchY: cint16;
    touchXpx, touchYpx: cint16;
    touchZ1, touchZ2: cint16;
    tdiode1, tdiode2: cuint16;
    pad1,pad2 : byte; //padding
    buttons: cuint16;
    pad3,pad4 : byte; //padding
    ...etc
    [/pascal]

    Also my first guess would be that the c/pascal alignment could
    differ at the last 8-bit fields: mailRead, mailBusy: cuint8;
    ZGameEditor - Develop 64kb games for Windows.
    Thrust for Vectrex - ROM-file and 6809 source code.

  5. #15

    [C related] Structs, records, pointers...

    So, I resolved that alignment issue. To tell the truth it was the effect and not the cause... :roll:

    Now I have another problem (I hope it will be the last one...). I have a function in a c library that requires as parameter a pointer to a void function:

    Code:
    typedef void (* VoidFunctionPointer)(void);
    void irqSet(IRQ_MASK irq, VoidFunctionPointer handler);
    I have translated it as:
    [pascal]procedure irqSet(irq: IRQ_MASK; handler: Pointer); cdecl; external;[/pascal]

    and it works if I use it in this way:

    [pascal]irqSet(IRQ_VBLANK, @myProcedure);[/pascal]

    Now the problem comes if I try to pass to irqSet a void function that is implemented in another c library:
    Code:
    extern void Wifi_Interrupt();
    translated as:
    [pascal]procedure Wifi_Interrupt(); cdecl; external;[/pascal]
    hangs on:
    [pascal]irqSet(IRQ_WIFI, @Wifi_Interrupt);[/pascal] :scratch:
    Get your fpc4gba copy now!
    Get your fpc4nds copy now!

  6. #16

    [C related] Structs, records, pointers...

    would this make any difference?

    [pascal]type
    VoidFunctionPointer = procedure; cdecl;[/pascal]

    [pascal]procedure irqSet(irq: IRQ_MASK; handler: VoidFunctionPointer); cdecl; external;[/pascal]
    Peregrinus, expectavi pedes meos in cymbalis
    Nullus norvegicorum sole urinat

  7. #17

    [C related] Structs, records, pointers...

    Unfortunately, the only difference is that in this way does not work for pascal procedures too
    Get your fpc4gba copy now!
    Get your fpc4nds copy now!

Page 2 of 2 FirstFirst 12

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •