Thread: unexpected segmentation fault

  1. #1
    Registered User
    Join Date
    Mar 2009
    Location
    Bozen
    Posts
    95

    unexpected segmentation fault

    The faulty code for the project is in
    trunk - sscompiler - Project Hosting on Google Code
    It includes a makefile.
    if you run: ssCompiler.out and then type int main(int c){} it will give a segmentation fault.

    If you try the following main, it will work correctly (see output).
    The unexpected thing is that when the above project fails is in addFunction("int", NULL, "foo") (with the same hard-coded parameters).

    Unfortunately the debugger couldn't help me with the yacc project, while in the main below, everything works!

    Immensly grateful if someone could try out my claims, and point me out. I recall there where compiler advocates on board, hopefully yacc experts too.


    Code:
    int main(int argc, char** argv) {
    
    /*
        list* fList = newFunct("int",NULL, "foo");
    */
        addFunction("int", NULL, "foo");
    /*
        addFunction("int", NULL, "bar");
    */
        printFList(fList);
        assert (findFunc(fList, "foo"));
    /*
        assert (findFunc(fList, "bar"));
    */
    
        return (EXIT_SUCCESS);
    }

  2. #2
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065
    Code:
    int main(int c){}
    The standard says the construct for main is:

    int main(void);

    OR

    int main(int argc, char **argv);

    Or any char ** type identifier (that'd be char *argv[] and char argv[][])

  3. #3
    Registered User
    Join Date
    Mar 2009
    Location
    Bozen
    Posts
    95
    Then try
    Code:
     void foo(int b){}
    . It was just any method definition with an argument.

  4. #4
    Registered User
    Join Date
    Mar 2009
    Location
    Bozen
    Posts
    95
    I guess I found the solution. Still to verify, though.

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by Kennedy View Post
    Code:
    int main(int c){}
    The standard says the construct for main is:

    int main(void);

    OR

    int main(int argc, char **argv);

    Or any char ** type identifier (that'd be char *argv[] and char argv[][])
    It also allows for "some other implementation defined manner" as well. So while not portable, you could write a compiler to allow it to take whatever you need in your environment.


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

  6. #6
    Registered User
    Join Date
    Mar 2009
    Location
    Bozen
    Posts
    95
    the issue I'm having is that in the yacc.y file I define a global list fList = NULL; I then want addFunction to add to it. The problem is that when it receives fList, it isn't NULL, although I set it so in the main() of yacc, and right in the declaration line. If I set it to NULL in the line before addFunction call in yacc.y, it works. Any suggestions?

  7. #7
    Registered User
    Join Date
    May 2010
    Location
    Naypyidaw
    Posts
    1,314
    Is it at the end of yacc grammar?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Errors including <windows.h>
    By jw232 in forum Windows Programming
    Replies: 4
    Last Post: 07-29-2008, 01:29 PM
  2. Segmentation fault
    By bennyandthejets in forum C++ Programming
    Replies: 7
    Last Post: 09-07-2005, 05:04 PM
  3. Segmentation fault
    By NoUse in forum C Programming
    Replies: 4
    Last Post: 03-26-2005, 03:29 PM
  4. Locating A Segmentation Fault
    By Stack Overflow in forum C Programming
    Replies: 12
    Last Post: 12-14-2004, 01:33 PM
  5. Segmentation fault...
    By alvifarooq in forum C++ Programming
    Replies: 14
    Last Post: 09-26-2004, 12:53 PM