Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 134893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T06:41:44+00:00 2026-05-11T06:41:44+00:00

For my Programming 102 class we are asked to deliver C code that compiles

  • 0

For my Programming 102 class we are asked to deliver C code that compiles and runs under Linux. I don’t have enough spare space on my hard drive to install Linux alongside Windows, and so I use cygwin to compile my programs.

The most recent program I had to give in compiles and runs fine under cygwin. It compiles fine under Linux, but half-way through execution produces a segmentation fault. I explained this to the grad student who gives us class and he said that cygwin’s version of GCC allows for sloppier code to be compiled and executed.

The few references I have found via google haven’t been conclusive. One thread I found said that the cause for the seg fault under Linux is a memory leak. Why would this not affect the cygwin version?

I would use the University’s computers, but I can’t use Subversion on them which would significantly hinder my efforts. (I’m new to coding and often need to be able to be able to revert to X revisions ago).

Is cygwin’s version of GCC really more ‘lax’ with the code it compiles? If so, are there any obvious issues to look out for when coding? Are there any alternatives for being able to write code that will run under Linux?

Edit

Thanks for the replies. I wasn’t explicit enough in my original post: that there is a bug in my code was pretty much a given for me (I am quite new to programming, and really green when it comes to C, after all). My TA implied cygwin’s GCC is a less reliable compiler -allowing for much sloppier code to run- than the one found under GNU/Linux. I found this strange and so had a search on the internet, but couldn’t really find any references to that fact.

More than blaming the compiler vs. my code, I was wondering what the reason could be for the program to run under Windows and crash under Linux. The replies re: different memory managers and heap/stack layout under Windows/Linux were illustrating in that regard.

Would the conclusion that cygwin’s GCC is just as ‘good’ as GNU/Linux’, and it’s the underlying operating systems/sheer luck that my buggy program runs under one and not the other be pretty much correct?

Regarding posting the source code, it’s a homework assignment so I’d prefer to find the issue myself if at all possible 🙂

Edit 2

I’ve accepted jalf’s answer as it talks about what makes the program run under Windows and not under Linux, which was what I really wanted to know. Thanks to everyone else who contributed, they were all very interesting and informative replies.

When I’ve found the issue and fixed it I’ll upload a zip file with all the source code of this non-working version, in case anyone is curious to see what the hell I did 🙂

Edit 3

For those interested in seeing the code, I found the problem, and it was indeed due to pointers. I was trying to return a pointer from a function. The pointer I was trying to return was being declared inside the function and so was being destroyed once the function executed. Problematic code is commented out on lines 22-24.

Feel free to ridicule my code.

/** *  Returns array of valid searches based on current coordinate */ void determine_searches(int row, int col, int last_row, int last_col, int *active_search){     // define coordinate categories and related valid search directions     int Library0[] = {2, 3, 4, -1};     int Library1[] = {4, 5, 6, -1};     int Library2[] = {2, 3, 4, 5, 6, -1};     int Library3[] = {0, 1, 2, 3, 4, 5, 6, 7, -1};     int Library4[] = {0, 1, 2, -1};     int Library5[] = {0, 6, 7, -1};     int Library6[] = {0, 1, 2, 6, 7, -1};     int Library7[] = {0, 1, 2, 3, 4, -1};     int Library8[] = {0, 4, 5, 6, 7, -1};      int * Library[] = {          Library0, Library1, Library2,         Library3, Library4, Library5,         Library6, Library7, Library8,     };      // declare (and assign memory to) the array of valid search directions that will be returned     //int *active_search;     //active_search = (int *) malloc(SEARCH_DIRECTIONS * sizeof(int));       // determine which is the correct array of search directions based on the current coordinate     // top left corner         int i = 0;     if(row == 0 && col == 0){         while(Library[0][i] != -1){             active_search[i] = Library[0][i];             i++;         }     }     // top right corner     else if(row == 0 && col == last_col){         while(Library[1][i] != -1){             active_search[i] = Library[1][i];             i++;         }     }     // non-edge columns of first row     else if(row == 0 && (col != 0 || col != last_col)){         while(Library[2][i] != -1){             active_search[i] = Library[2][i];             i++;         }     }     // non-edge coordinates (no edge columns nor rows)     else if(row != 0 && row != last_row && col != 0 && col != last_col){         while(Library[3][i] != -1){             active_search[i] = Library[3][i];             i++;         }     }     // bottom left corner     else if(row == last_row && col == 0){         while(Library[4][i] != -1){             active_search[i] = Library[4][i];             i++;         }     }     // bottom right corner     else if(row == last_row && col == last_col){         while(Library[5][i] != -1){             active_search[i] = Library[5][i];             i++;         }     }     // non-edge columns of last row     else if(row == last_row && (col != 0 || col != last_col)){         while(Library[6][i] != -1){             active_search[i] = Library[6][i];             i++;         }     }     // non-edge rows of first column     else if((row != 0 || row != last_row) && col == 0){         while(Library[7][i] != -1){             active_search[i] = Library[7][i];             i++;         }     }     // non-edge rows of last column     else if((row != 0 || row != last_row) && col == last_col){         while(Library[8][i] != -1){             active_search[i] = Library[8][i];             i++;         }     }     active_search[i] = -1; } 
  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T06:41:45+00:00Added an answer on May 11, 2026 at 6:41 am

    Like others have said, you might want to post some of your code here, even if that’s not the real point of your question. It might still be a good learning experience to have everyone here poke through your code and see if they can find what caused the segfault.

    But yeah, the problem is that there are so many platform-dependent, as well as basically random, factors influencing a C program. Virtual memory means that sometimes, accessing unallocated memory will seem to work, because you hit an unused part of a page that’s been allocated at some earlier point. Other times, it’ll segfault because you hit a page that hasn’t been allocated to your process at all. And that is really impossible to predict. It depends on where your memory was allocated, was it at the edge of a page, or in the middle? That’s up to the OS and the memory manager, and which pages have been allocated so far, and…… You get the idea. Different compilers, different versions of the same compilers, different OS’es, different software, drivers or hardware installed on the system, anything can change whether or not you get a segfault when you access unallocated memory.

    As for the TA’s claim that cygwin is more ‘lax’, that’s rubbish, for one simple reason. Neither compiler caught the bug! If the ‘native’ GCC compiler had truly been less lax, it would have given you an error at compile-time. Segfaults are not generated by the compiler. There’s not much the compiler can do to ensure you get a segfault instead of a program that seemingly works.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 101k
  • Answers 101k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You could use the -> operator to reference an instance/object… May 11, 2026 at 8:07 pm
  • Editorial Team
    Editorial Team added an answer If you really have to do this conversion, you should… May 11, 2026 at 8:07 pm
  • Editorial Team
    Editorial Team added an answer The following code will disable verification of the certificate. Note… May 11, 2026 at 8:07 pm

Related Questions

I am developing a simple platform game in Java using BlueJ. Over the next
For my programming class I have to write a linked list class. One of
For my programming languages class, I'm writing a research paper on some papers by
I'm creating an RSS (and/or Atom) feed for my website. Now, I can immediately

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.