-1

we have a school project and it requires our C programs to work on Linux and is c99 compatible. Since I am working on Windows 10, I installed Cygwin and assumed that if it will compile in cygwin, it will most certainly work in Linux. It works fine with windows and I tried to compile it in cygwin and it works as well. So can I assure that it will work in Linux and is C99 Compatible? If no, why not? I am only using stdio and stdlib

13
  • 2
    Lol instead of voting, please enlighten me. You can help other people that way Sep 12, 2016 at 12:08
  • it's difficult to help you with so little information, specially without code. But if you just use standard library, without writing filename inside your code, it will probably compile and run on linux as on you computer. Be sure to use "-Wall" flag when you compile and have no warning
    – Garf365
    Sep 12, 2016 at 12:14
  • 1
    If the code is plain C, and not using anything platform specific, then yes it should work on any compliant compiler. Note that the code should work, but not the executable file. C is only source-code platform independent. Sep 12, 2016 at 12:15
  • also, to check on other platforms, you can use online compilers like ideone or coliru
    – Garf365
    Sep 12, 2016 at 12:16
  • Sorry I didn't include the code because my classmates might find this question and see my code and use it in their projects. My teacher will kill me lol. Alright thanks, btw I forgot to mention that I also used string.h, will that be okay? Sep 12, 2016 at 12:20

2 Answers 2

2

You can never be sure. Even though your program seems to work it may still contain bugs that invoke undefined behaviour.

However, you can reduce the risk of malfunctions by using best practice, for example:

Heed compiler warnings

Turn up compiler warning. For example:

gcc -Wall -Wextra -pedantic -std=c99

This turns up the warning level to a fairly high level. . Compiler warnings are often indications of bugs, so fix them all. To ensure that you fix them, add -Werror so you can't run your code until all warnings have been fixed.

-std=c99 tells the compiler to use the rules for the C99 version of the C standard. The current version is C11 (-stdc11). This is an important flag, and if omitted gcc defaults to the older C89 standard.

Use a tool to detect invalid use of memory

Tools like Valgrind (linux) will report common memory bugs like buffer overruns and memory leaks. Not sure which tool is most often used in Windows, but there is a wide selection listed here.

5
  • -Wextra perhaps? -Wall is just the baseline, really (and a really annoying misnomer for that). And that should probably be -std=c11 by now.
    – DevSolar
    Sep 12, 2016 at 13:41
  • @DevSolar -Wextra is good. Adding! OP explicitly mentioned that the code should be C99. I've added some extra information on -std for clarification. Sep 12, 2016 at 14:45
  • -Werror perhaps? Also, valgrind would be a Linux tool.
    – jxh
    Sep 12, 2016 at 16:20
  • @jxh Thanks. I added a link to a list of Windows substitutes and added a mention of -Werror. Sep 13, 2016 at 7:17
  • Also, most uninitialized variable warnings won't show up unless optimization is also enabled.
    – jxh
    Sep 13, 2016 at 15:34
0

If it is vanilla C99, at 99.9% if works on Cygwin it will work on any Linux. I never saw a case that did not work.

Reverse is not always true, I would estimate ~ 98%, as linking could give some headache on some corner case.

6
  • If it's vanilla C99, it will run on any platform with a C99 compiler. Not 99.9% of the time, always. That's the whole point of the language standard. Cygwin is for something else entirely -- those parts of the Unix / Linux API that are not covered by C99.
    – DevSolar
    Sep 12, 2016 at 12:44
  • 1
    Always is the theory. Also C99 compliance of a compiler can not be really proved with a lot of efforts that is NEVER there.
    – matzeri
    Sep 12, 2016 at 12:47
  • If it doesn't work it's because either the program, the compiler, or the library is non-compliant. And I have implemented large parts of a C99 library, including tests, for cross-platform use. But that is beside the point. Your answer is not answering the question IMHO.
    – DevSolar
    Sep 12, 2016 at 12:50
  • Can you state for every compiler variant used on every Linux distribution that they are C99 100% compliant ? I doubt. For the rest feel free to disagree with me.
    – matzeri
    Sep 12, 2016 at 13:03
  • This question is not about compiler bugs or limits of any given implementation. It is about Cygwin, and how much a user could rely on "works on Cygwin" to mean "works on Linux". To which your answer is OT. And since you seem to be reluctant to improve it, downvoted.
    – DevSolar
    Sep 12, 2016 at 13:06

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.