CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2015
    Posts
    2

    Error expected identifier before ' &' token

    Hullo everyone, i have been trying to work around this error for a while but i just can not get it fixed. thought i would ask for some help on this forum. I have a struct called alt_dev_s with one of the elements as int(*open) (alt_fd* fd. const char* name, int flags, int mode) to open the file descriptor

    when i try to access the element in my main function i get the above error. Here is my code sample. Thanks in advance!!

    Code:
    #define ERGO_CMD_GET_ADDRESS   0x11
    #define ERGO_CMD_RUN_DATA      0x40
    #define ERGO_CMD_SET_WATT     0x51
    #define UART_MAX_DATA       20
    
    /*Global Variables*/
    ergo_run_data_t ergo_run_data;
    u_int8_t ergo_adr_int;
    
    /* External Functions that are called in the main function*/
    
    int altera_16550_uart_read_fd(alt_fd* fd, char* ptr, int len);
    int altera_16550_uart_write_fd(alt_fd* fd, const char* buffer, int space);
    int altera_16550_uart_ioctl_fd(alt_fd* fd, int req, void* arg);
    int altera_16550_uart_close_fd(alt_fd* fd);
    //int (*open) (alt_fd* fd, const char* name, int flags, int mode);
    void ergo_get_address();
    void ergo_get_run_data(void);
    void ergo_set_watt(u_int8_t ergo_adr_int, u_int8_t watt);
    void ergo_reset(u_int8_t ergo_adr_int);
    void ergo_break(void);
    
    
    int main()
    {
        alt_fd* fd;
        struct alt_dev_s alt_dev;
     /*Open File Descriptor*/
    
    // I am getting the error on this line
    
     alt_dev -> &(open) (&(alt_fd) {"/dev/ttyUSB0"}, &(const char) {ttyUSB0},0,O_RDWR|O_NOCTTY|O_NONBLOCK);  
           //Error Handling
    	if ( fd < 0 )
    	{
    	printf("Error beim oeffnen");
    	}
    
        return 0;
    }

  2. #2
    Join Date
    Mar 2012
    Posts
    3

    Re: Error expected identifier before ' &' token

    You are confusing struct alt_dev_s and alt_dev types.
    Function call should look like this:
    Code:
    alt_fd *fd = NULL; // needs to be initialized with some value
    struct alt_dev_s alt_dev;
    int file_desc = alt_dev.open(fd, "/dev/ttyUSB0", 0, O_RDWR | O_NOCTTY | O_NONBLOCK);
    if (file_desc < 0)
    {
        printf("Error beim oeffnen");
    }
    Last edited by DRK82; April 2nd, 2015 at 03:57 AM.

Tags for this Thread

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured