Thread: A confusing syntax error

  1. #1
    Registered User
    Join Date
    Oct 2003
    Posts
    27

    A confusing syntax error

    Here is a snippet of my program.

    Code:
    void
    add_trans(Dict *dict, char *source, char *target)
    {
        if (source != dict->*entry->source){
    	dict->*entry->source = source;
    	dict->size++;
    	insert(dict->*entry->trans->target, target);
        }
    }
    While compiling it's giving me this error:

    In function `add_trans':
    error: syntax error before '*' token
    error: syntax error before '*' token
    Why is this syntaxt wrong?

    Many thanks.

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    I think your compiler can't figure out what 'Dict' is.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
    if (source != dict->*entry->source){
    	dict->*entry->source = source;
    What is entry?

    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    Registered User
    Join Date
    Oct 2003
    Posts
    27
    The structures are defined in my headerfile.

    Entry:
    Code:
    typedef struct {
        char *source;
        Target_node *trans;
    } Entry;
    Dict:
    Code:
    typedef struct {
        Entry **entries;
        int size;
        int max;
    } Dict;
    This is the right way to do it, right? That's why I find the syntax error very confusing and I don't know why there is a "syntax error before *".

    Many Thanks
    Last edited by sjalesho; 03-01-2004 at 05:57 PM.

  5. #5
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Code:
    typedef struct {
        Entry **entries;
        int size;
        int max;
    } Dict;
    
    dict->*entry->source = source;
    Look at the bolded sections.

    Also is **entries a pointer to a pointer or a pointer an array of pointers?
    If its an array of pointers like I'm thinking then you would need something like:
    Code:
    dict->entries[i]->source

  6. #6
    Registered User
    Join Date
    Oct 2003
    Posts
    27
    Thantos,

    Many thanks. A pointer to a pointer gives me a headache, but I think I got that one right by not omitting a pointer.

    My compiler is giving me the same errors for these 2 lines:

    Code:
    if (source != dict->*entry->source){
    Code:
    insert(dict->*entry->trans->target, target);
    Before that function I have already setup the insert function, but I don't think it's needed to post it. It's related to the syntax...

  7. #7
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Off the top of my head I'd say it should be
    Code:
    source != dict->(*entry)->source
    Last edited by Thantos; 03-01-2004 at 06:40 PM.

  8. #8
    Registered User
    Join Date
    Oct 2003
    Posts
    27
    Originally posted by Thantos
    Off the top of my head I'd say it should be
    Code:
    source != dict->(*entry)->source
    Then it's giving the syntax error

    Code:
    parse error before '(' token

  9. #9
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Tried to recreate your structures and heres what I got
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    typedef struct
    {
      char x;
      int y;
    }Entry;
    
    typedef struct
    {
      Entry **test;
      int a;
      int b;
    }Dict;
    
    void foo (Dict *);
    
    int main(void)
    {
      Entry node={'b', 5}, *point=&node;
      Dict something={&point, 15, 20};
    
      foo (&something);
      return 0;
    }
    void foo (Dict *something)
    {
      printf("%c %d %d %d\n",
          something->test[0]->x,
          something->test[0]->y,
          something->a,
          something->b);
    }
    I tried every other way I could think of but something->test[0]->x was the only way I could get it to work.

  10. #10
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    (*dict->entry)->trans->target

    order of operations!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. PlaySound
    By cangel in forum C++ Programming
    Replies: 16
    Last Post: 10-08-2009, 05:29 PM
  2. How to monitor process creation?
    By markiz in forum Windows Programming
    Replies: 31
    Last Post: 03-17-2008, 02:39 PM
  3. error: template with C linkage
    By michaels-r in forum C++ Programming
    Replies: 3
    Last Post: 05-17-2006, 08:11 AM
  4. pointer to array of objects of struct
    By undisputed007 in forum C++ Programming
    Replies: 12
    Last Post: 03-02-2004, 04:49 AM
  5. UNICODE and GET_STATE
    By Registered in forum C++ Programming
    Replies: 1
    Last Post: 07-15-2002, 03:23 PM