Re: XForms: Whats Wrong?

From: T.C. Zhao (tc_zhao@yahoo.com)
Date: Sat Feb 26 2000 - 12:54:26 EST

  • Next message: T.C. Zhao: "Re: XForms: Formbrowser"

    # To subscribers of the xforms list from "T.C. Zhao" <tc_zhao@yahoo.com> :

    I am surprised that the compiler let the code pass.
    Anyway, declear the callback function outside the
    main() function:
    extern void cbx(int fd, void *data)
    and change the function the same way.

    Your program is very interesting in a weird way.
    It's fatally wrong but somehow it fooled the compiler.
    What FL_IO_CALLBACK cbx() does is declaring a function
    that returns a function pointer to a void (*)(int, void *)
    function, which your cbx function clearly does not do.
    However, the symbol cbx() does exist and it appears
    the linker took it. At the fl_set_io_callback() call,
    cbx() is executed, expecting it would return a function
    pointer. Of course it does not. Further at that time, the
    function that gets called is called as cbx(void).
     

    and modify the function

    --- Serge B Bromow <serge@omensys.com> wrote:
    > # To subscribers of the xforms list from Serge B Bromow
    > <serge@omensys.com> :
    >
    > OS = SCO OSR5
    > XF = v.88
    >
    > APP = Simple test to read a serial touch screen controller. Callback
    > is
    > called when
    > touch screen is touched.
    >
    > FORM = Has 2 buttons. 1 to test xforms(Ok), second to exit
    > program(Exit).
    >
    > RESULT = Application starts and callback is called, even before
    > data is available for reading on the port. When the touch screen is
    > touched a memory fault occurs (no output to STDOUT).
    >
    > Any thoughts!
    > --------------------------------------------------
    > #include "forms.h"
    > #include "cur.h"
    > #include<standard.h>
    >
    > FD_cur *fd_cur;
    >
    > long l = 0;
    >
    > int main(int argc, char *argv[])
    > {
    > FL_IO_CALLBACK cxb();
    >
    > int fd;
    >
    > /* Open serial device for reading */
    > if( (fd = open("/dev/srs011", READ)) == FAIL ) {
    > printf("can't open touch screen\n");
    > exit(PASS);
    > }
    >
    > fl_initialize(&argc, argv, 0, 0, 0);
    > fd_cur = create_form_cur();
    >
    > fl_add_io_callback(fd, FL_READ, cxb(), &l);
    >
    > /* show the first form */
    > fl_show_form(fd_cur->cur,FL_PLACE_CENTERFREE,FL_FULLBORDER,"cur");
    >
    >
    > fl_do_forms();
    > return 0;
    > }
    >
    > FL_IO_CALLBACK cxb( int fd, long *data)
    > {
    > char c;
    >
    > /* Show Entry to Callback */
    > printf("touched, data = %ld\n", *data);
    >
    > /* Empty Queu */
    > while( rdchk( fd ) > NULL ) {
    > read(fd, &c, 512);
    > }
    > }
    > -----------------------------------------------------
    > Thanks for any help you can provide.
    >
    > Serge
    >
    >
    > _________________________________________________
    > To unsubscribe, send the message "unsubscribe" to
    > xforms-request@bob.usuhs.mil or see
    > http://bob.usuhs.mil/mailserv/xforms.html
    > XForms Home Page: http://world.std.com/~xforms
    > List Archive: http://bob.usuhs.mil/mailserv/list-archives/
    >
    >
    __________________________________________________
    Do You Yahoo!?
    Talk to your friends online with Yahoo! Messenger.
    http://im.yahoo.com
    _________________________________________________
    To unsubscribe, send the message "unsubscribe" to
    xforms-request@bob.usuhs.mil or see
    http://bob.usuhs.mil/mailserv/xforms.html
    XForms Home Page: http://world.std.com/~xforms
    List Archive: http://bob.usuhs.mil/mailserv/list-archives/



    This archive was generated by hypermail 2b29 : Sat Feb 26 2000 - 12:58:17 EST