segmentation fault

This is a discussion on segmentation fault within the C++ Programming forums, part of the General Programming Boards category; Hi, I am new to this forum.I am having a bit of problem while coding a program. I am facing ...

  1. #1
    Registered User
    Join Date
    Apr 2011
    Posts
    7

    segmentation fault

    Hi,
    I am new to this forum.I am having a bit of problem while coding a program. I am facing a segmentation fault.
    Code:
    int main()
    {
    //calls
    fn();
    printf("Can i be seen!!");
    }
    void fn()
    {
    //some code here
    printf("Can come here without any problem");
    }
    Now I get the output till the printf...
    I even get the message
    Can come here without any problem
    But get a segmentation fault immediately.
    I am not understanding why i am getting this message...


    Can anyone help me...

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Use fprintf(stderr...) or cerr for this kind of thing. Stdout (which printf uses) is buffered, meaning you can loose messages during segfaults which will mislead you.

    I have no idea about your current problem tho. What OS are you on?
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  3. #3
    Registered User
    Join Date
    Apr 2011
    Posts
    7
    I am using Ubuntu lucid lynx 10.04 and using a g++ compiler...

    This is not the actual code but the actual code is similar

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    2,758
    Does the code you supplied exhibit the problems you are reporting? If not post a sample of the code that illustrates the problem.


    Jim

  5. #5
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,650
    No, it's not all his code. Instead it's all his code that couldn't cause a seg fault.

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,555
    > This is not the actual code but the actual code is similar
    Then you basically destroyed whatever the bug was.

    Feel free to edit down a copy of your code to a small example which still shows the same problem (delete everything that would run AFTER the problem for example).
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Re: Segmentation fault
    By turkish_van in forum C Programming
    Replies: 8
    Last Post: 01-20-2007, 04:50 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, 02:29 PM
  4. Locating A Segmentation Fault
    By Stack Overflow in forum C Programming
    Replies: 12
    Last Post: 12-14-2004, 12:33 PM
  5. Segmentation fault...
    By alvifarooq in forum C++ Programming
    Replies: 14
    Last Post: 09-26-2004, 12:53 PM

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