Segmentation fault, core dumped

This is a discussion on Segmentation fault, core dumped within the C Programming forums, part of the General Programming Boards category; I'm compiling with gcc and with -O2 optimisation. Here's the code: Code: #include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <sys/io.h> ...

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    9

    Segmentation fault, core dumped

    I'm compiling with gcc and with -O2 optimisation.
    Here's the code:

    Code:
    #include <stdio.h>
    #include <unistd.h>
    #include <stdlib.h>
    #include <sys/io.h>
    #define PORT1 0x3F8
    
    main()
    {
    
    if (ioperm(PORT1, 4, 1)) {perror("ioperm"); exit(1);}
    char a;
    outb_p(0 , PORT1 + 1); /* No interupts*/
    outb_p(0x80 , PORT1 + 3); /* DLab*/
    outb_p(0x02 , PORT1 + 0); /*Baud Rate--Low byte?*/
    outb_p(0x03 , PORT1 + 3); /* * 8 Bits, No Parity, 1 Stop Bit */
    /*outb_p(0x0B , PORT1 + 4); /* Turn on DTR, RTS, and OUT2 */
    
    /*Roomba Control*/
    printf("Roomba go!\n");
    
    outb_p(128, PORT1); /* Begin SCI*/
    outb_p(130, PORT1); /* Go To Safe Mode*/
    outb_p(132, PORT1); /* Go To Full Mode*/
    
    outb_p(137, PORT1);
    outb_p(255, PORT1);
    outb_p(56, PORT1);
    outb_p(128, PORT1);
    outb_p(0, PORT1);
    
    while(a != 'a')
    {
    a = getchar();
    }
    printf("Roomba stop!\n");
    
    outb_p(137, PORT1);
    outb_p(0, PORT1);
    outb_p(0, PORT1);
    outb_p(0, PORT1);
    outb_p(0, PORT1);
    return(0);
    }
    I have to use sudo to run it or the ioperm won't work. I get a segmentation fault (core dumped) error.

  2. #2
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,424
    Are you compiling as C++ Or C99?

    What line does the segfault happens? Could you remove all lines afterwards and explain the function you are calling in this line?
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  3. #3
    Banned
    Join Date
    May 2007
    Location
    Berkeley, CA
    Posts
    329
    Hmmm..... the coding style and question looks remarkably similar to the following

    http://www.roombareview.com/chat/viewtopic.php?t=5198

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What am I doing worng? Segmentation fault, core dump
    By cookie in forum C Programming
    Replies: 4
    Last Post: 06-08-2007, 09:59 AM
  2. Locating A Segmentation Fault
    By Stack Overflow in forum C Programming
    Replies: 12
    Last Post: 12-14-2004, 12:33 PM
  3. Runtime error 'segmentation fault (core dumped)'
    By mikemccready in forum C Programming
    Replies: 2
    Last Post: 03-17-2003, 06:14 AM
  4. Segmantation Fault (core dumped) error
    By Vinnie66 in forum C Programming
    Replies: 6
    Last Post: 03-25-2002, 12:34 PM
  5. Segmentation fault (core dumped)
    By JYSN in forum C Programming
    Replies: 1
    Last Post: 02-21-2002, 02:24 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21