Thread: Struct error

  1. #16
    Registered User
    Join Date
    May 2007
    Posts
    46
    Quote Originally Posted by hk_mp5kpdw View Post
    Well, for the code you've provided, I also get undefined function messages for receiveMsgSpeechRecognition and also RecogniseWordInSentence which would account for those errors. If the compiler doesn't understand what those two functions are then it will assume they return an int and then you get the errors because it can't convert an int to type struct sentencestruct. So, where are the prototypes for those two functions located?

    Also, instances of variables should be restricted to the source files and not put into headers like you've done in global.h. Header files should generally contain function prototypes and extern statements and struct definitions while the source file(s) that #include those headers contain the actual instances of any variables.
    The two messages is alike and thats right, i only posted the receiveMsgSpeechRecognition-method in file: speechRecognition.c.. Just outcomment the other one..
    ..... DAMN ME....... The most obvious thing just happend.. The definition in the c-file is good enough, but the declaretion in the header speechRecognition.h have a return-type of int... I changed it when i reconstructed the code in the c-file..

    But It's global variables that should be avaliable everywhere, in all the files..? It should be possible to change them from all c-files... Theres an excact reason for that.. How should I do it else..?

  2. #17
    Registered User
    Join Date
    May 2007
    Posts
    46
    Once again I thought I had the error but appertently not..

  3. #18
    Registered User
    Join Date
    May 2007
    Posts
    46
    Okay I might have found the problem, but why..?!

    I have changed a bit...

    c-file:
    Code:
    void RecogniseWordInSentence(struct sentencestruct ........) {...}
    if I define it in the header like this:
    Code:
    void RecogniseWordInSentence(struct sentencestruct *);
    i get same error:
    [ex44@jensen final]# make
    cc -c -o control-module.o control-module.c
    control-module.c: In function `speechrecognitioncontrol':
    control-module.c:541: error: incompatible type for argument 1 of `RecogniseWordInSentence'
    make: *** [control-module.o] Error 1


    But if I remove it from header or refine header to:
    Code:
    void RecogniseWordInSentence();
    then it accepts it.. I think it is strange..? And can I expect i works without..?

  4. #19
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Code:
    void RecogniseWordInSentence(struct sentencestruct ........)
    I hope this isn't what you really have in the file.

  5. #20
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Quote Originally Posted by sniper83 View Post
    The two messages is alike and thats right, i only posted the receiveMsgSpeechRecognition-method in file: speechRecognition.c.. Just outcomment the other one..
    ..... DAMN ME....... The most obvious thing just happend.. The definition in the c-file is good enough, but the declaretion in the header speechRecognition.h have a return-type of int... I changed it when i reconstructed the code in the c-file..

    But It's global variables that should be avaliable everywhere, in all the files..? It should be possible to change them from all c-files... Theres an excact reason for that.. How should I do it else..?
    Let's say you have a project with 2 source files (example1.c and example2.c) and you need to have globals that can be used/accessed in both source files. You put the instances/declarations of the globals in one of the files and then have a header (example.h) with all those variables but declared with extern as well.

    example.h
    Code:
    #ifndef EXAMPLE_H
    #define EXAMPLE_H
    
    // These externs represent some globals in example1.c
    extern int global_ex1_1;
    extern int global_ex1_2;
    
    // These externs represent some globals in example2.c
    extern int global_ex2_1;
    extern int global_ex2_2;
    
    #endif
    example1.c
    Code:
    // By including example.h, we can also access the globals declared in example2.c
    #include "example.h"
    
    int global_ex1_1;
    int global_ex1_2;
    example2.c
    Code:
    // By including example.h, we can also access the globals declared in example1.c
    #include "example.h"
    
    int global_ex2_1;
    int global_ex2_2;
    You have it backwards currently, many of your extern'd variables are in the source file while the instances themselves are in the header file global.h. If you were to ever #include global.h (as it stands now) in two different source files then you'd get tons of errors when linking your project because of multiple definitions of the same variable name.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  6. #21
    Registered User
    Join Date
    May 2007
    Posts
    46
    Quote Originally Posted by robwhit View Post
    Code:
    void RecogniseWordInSentence(struct sentencestruct ........)
    I hope this isn't what you really have in the file.
    Of cause not..
    Should have been
    Code:
    void RecogniseWordInSentence(struct sentencestruct ........){....}
    WOW.. I cant scribe * s s in one word... :S Okay "........" means *ass minus the a..
    EDIT: Redifined to ds instead of ss
    Code:
    void RecogniseWordInSentence(struct sentencestruct *ds){....}
    Thanks hk_mp5kpdw, Then I'll turn it upside down and do it right this time..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  2. Why wont my function exit correctly?
    By LightsOut06 in forum C Programming
    Replies: 2
    Last Post: 10-09-2005, 09:23 PM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. UNICODE and GET_STATE
    By Registered in forum C++ Programming
    Replies: 1
    Last Post: 07-15-2002, 03:23 PM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM